diff options
| author | Dan Engelbrecht <[email protected]> | 2024-01-22 13:21:55 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-22 13:21:55 +0100 |
| commit | cccb2d71885d1211b3eb2fc9531826457846b014 (patch) | |
| tree | 9424b687d76bf937304ce14aaeef9308a31e02c2 /src/zencore/jobqueue.cpp | |
| parent | make sure to advance read buffer pointer in BasicFileWriter::Write (#633) (diff) | |
| download | zen-cccb2d71885d1211b3eb2fc9531826457846b014.tar.xz zen-cccb2d71885d1211b3eb2fc9531826457846b014.zip | |
jobqueue - allow multiple threads to report progress/messages (#635)
jobqueue - add AbortReason and properly propagate error when running async command
Diffstat (limited to 'src/zencore/jobqueue.cpp')
| -rw-r--r-- | src/zencore/jobqueue.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/zencore/jobqueue.cpp b/src/zencore/jobqueue.cpp index 4bcc5c885..e92817431 100644 --- a/src/zencore/jobqueue.cpp +++ b/src/zencore/jobqueue.cpp @@ -258,7 +258,8 @@ public: .Status = Status, .State = {.CurrentOp = Job.State.CurrentOp, .CurrentOpPercentComplete = Job.State.CurrentOpPercentComplete, - .Messages = std::move(Job.State.Messages)}, + .Messages = std::move(Job.State.Messages), + .AbortReason = Job.State.AbortReason}, .CreateTime = JobClock::TimePointFromTick(Job.CreateTick), .StartTime = JobClock::TimePointFromTick(Job.StartTick), .EndTime = JobClock::TimePointFromTick(Job.EndTick), @@ -296,7 +297,7 @@ public: void ReportMessage(JobId Id, std::string_view Message) { - QueueLock.WithSharedLock([&]() { + QueueLock.WithExclusiveLock([&]() { auto It = RunningJobs.find(Id.Id); ZEN_ASSERT(It != RunningJobs.end()); It->second->State.Messages.push_back(std::string(Message)); @@ -305,7 +306,7 @@ public: void ReportProgress(JobId Id, std::string_view CurrentOp, uint32_t CurrentOpPercentComplete) { - QueueLock.WithSharedLock([&]() { + QueueLock.WithExclusiveLock([&]() { auto It = RunningJobs.find(Id.Id); ZEN_ASSERT(It != RunningJobs.end()); It->second->State.CurrentOp = CurrentOp; @@ -363,8 +364,9 @@ public: ZEN_DEBUG("Background job {}:'{}' aborted. Reason: '{}'", CurrentJob->Id.Id, CurrentJob->Name, Ex.what()); QueueLock.WithExclusiveLock([&]() { CurrentJob->State.Messages.push_back(Ex.what()); - CurrentJob->EndTick = JobClock::Now(); - CurrentJob->WorkerThreadId = 0; + CurrentJob->State.AbortReason = Ex.what(); + CurrentJob->EndTick = JobClock::Now(); + CurrentJob->WorkerThreadId = 0; RunningJobs.erase(CurrentJob->Id.Id); AbortedJobs.insert_or_assign(CurrentJob->Id.Id, std::move(CurrentJob)); }); @@ -503,7 +505,7 @@ TEST_CASE("JobQueue") RemainingJobs.push_back(Id); break; case JobQueue::Status::Aborted: - ZEN_DEBUG("{} aborted. Reason: '{}'", Id.Id, Join(CurrentState->State.Messages, " "sv)); + ZEN_DEBUG("{} aborted. Reason: '{}'", Id.Id, CurrentState->State.AbortReason); break; case JobQueue::Status::Completed: ZEN_DEBUG("{} completed. '{}'", Id.Id, Join(CurrentState->State.Messages, " "sv)); |