FOSSredder 0.5.0
Loading...
Searching...
No Matches
JobSystem.h
Go to the documentation of this file.
1
5
6#pragma once
7
9
10#include <atomic>
11#include <cstddef>
12#include <memory>
13#include <optional>
14#include <string>
15
17class IErrorReporter;
18}
19
20namespace core::jobs {
21
22class Scheduler;
23class SlotLimiter;
24
25class JobSystem {
26public:
32 explicit JobSystem(std::shared_ptr<core::ports::diagnostics::IErrorReporter> errorReporter,
33 std::size_t workers = 0);
34
39
43 JobSystem(const JobSystem&) = delete;
44
49 JobSystem& operator=(const JobSystem&) = delete;
50
55 JobSystem(JobSystem&& other) noexcept;
56
62 JobSystem& operator=(JobSystem&& other) noexcept;
63
69 [[nodiscard]] JobId submit(JobKind kind = JobKind::Generic);
70
75 void start(const JobId& id);
76
81 void publish(const JobEvent& event);
82
88 void fail(const JobId& id, const std::string& error);
89
94 void finish(const JobId& id);
95
101 [[nodiscard]] std::shared_ptr<std::atomic<bool>> cancelFlag(const JobId& id) const;
102
108 [[nodiscard]] std::shared_ptr<std::atomic<bool>> pauseFlag(const JobId& id) const;
109
114 [[nodiscard]] Scheduler& scheduler();
115
120 [[nodiscard]] SlotLimiter& slotLimiter();
121
129
135 void unsubscribe(const JobId& id, SubscriptionId subId);
136
141 void cancel(const JobId& id);
142
147 void pause(const JobId& id);
148
153 void resume(const JobId& id);
154
160 std::optional<JobSnapshot> snapshot(const JobId& id) const;
161
165 void shutdown();
166
167private:
168 class Impl;
169 std::unique_ptr<Impl> impl_;
170};
171
172}
Defines shared job identifiers, states, events, and snapshots.
void cancel(const JobId &id)
Cancel a job.
JobSystem & operator=(JobSystem &&other) noexcept
Move-assign a job system facade.
std::shared_ptr< std::atomic< bool > > cancelFlag(const JobId &id) const
Retrieve a job cancellation flag.
Definition JobSystem.cpp:92
void resume(const JobId &id)
Resume a paused job.
JobSystem(std::shared_ptr< core::ports::diagnostics::IErrorReporter > errorReporter, std::size_t workers=0)
Create a generic job system.
Definition JobSystem.cpp:55
~JobSystem()
Destroy the job system.
void start(const JobId &id)
Mark a job as running.
Definition JobSystem.cpp:72
void fail(const JobId &id, const std::string &error)
Mark a job as failed.
Definition JobSystem.cpp:82
void pause(const JobId &id)
Pause a running job.
void unsubscribe(const JobId &id, SubscriptionId subId)
Unsubscribe from job events.
JobSystem(JobSystem &&other) noexcept
Move a job system facade.
JobSystem(const JobSystem &)=delete
Copying a job system is disabled.
JobSystem & operator=(const JobSystem &)=delete
Copy-assigning a job system is disabled.
void shutdown()
Shut down the job system.
void publish(const JobEvent &event)
Publish a job event to subscribers and update its snapshot.
Definition JobSystem.cpp:77
std::shared_ptr< std::atomic< bool > > pauseFlag(const JobId &id) const
Retrieve a job pause flag.
Definition JobSystem.cpp:97
void finish(const JobId &id)
Mark a job as finished.
Definition JobSystem.cpp:87
SlotLimiter & slotLimiter()
Access the shared slot limiter.
std::optional< JobSnapshot > snapshot(const JobId &id) const
Retrieve a job snapshot.
JobId submit(JobKind kind=JobKind::Generic)
Create a new tracked job.
Definition JobSystem.cpp:67
Scheduler & scheduler()
Access the shared worker scheduler.
SubscriptionId subscribe(const JobId &id, JobEventCallback cb)
Subscribe to job events.
Runs background tasks on a bounded worker queue.
Definition Scheduler.h:55
Limits concurrent access to a bounded number of slots.
Definition Scheduler.h:27
Port for reporting structured diagnostic error events.
std::uint64_t SubscriptionId
Identifier for a job event subscription.
Definition JobTypes.h:88
std::string JobId
Stable identifier for one tracked job.
Definition JobTypes.h:21
JobKind
Classifies the high-level type of job.
Definition JobTypes.h:26
std::function< void(const JobEvent &)> JobEventCallback
Callback invoked for published job events.
Definition JobTypes.h:93
Event emitted when a job changes state or progress.
Definition JobTypes.h:52