FOSSredder 0.5.0
Loading...
Searching...
No Matches
core::jobs::JobSystem Class Reference

#include <JobSystem.h>

Classes

class  Impl

Public Member Functions

 JobSystem (std::shared_ptr< core::ports::diagnostics::IErrorReporter > errorReporter, std::size_t workers=0)
 Create a generic job system.
 ~JobSystem ()
 Destroy the job system.
 JobSystem (const JobSystem &)=delete
 Copying a job system is disabled.
JobSystem & operator= (const JobSystem &)=delete
 Copy-assigning a job system is disabled.
 JobSystem (JobSystem &&other) noexcept
 Move a job system facade.
JobSystem & operator= (JobSystem &&other) noexcept
 Move-assign a job system facade.
JobId submit (JobKind kind=JobKind::Generic)
 Create a new tracked job.
void start (const JobId &id)
 Mark a job as running.
void publish (const JobEvent &event)
 Publish a job event to subscribers and update its snapshot.
void fail (const JobId &id, const std::string &error)
 Mark a job as failed.
void finish (const JobId &id)
 Mark a job as finished.
std::shared_ptr< std::atomic< bool > > cancelFlag (const JobId &id) const
 Retrieve a job cancellation flag.
std::shared_ptr< std::atomic< bool > > pauseFlag (const JobId &id) const
 Retrieve a job pause flag.
Scheduler & scheduler ()
 Access the shared worker scheduler.
SlotLimiter & slotLimiter ()
 Access the shared slot limiter.
SubscriptionId subscribe (const JobId &id, JobEventCallback cb)
 Subscribe to job events.
void unsubscribe (const JobId &id, SubscriptionId subId)
 Unsubscribe from job events.
void cancel (const JobId &id)
 Cancel a job.
void pause (const JobId &id)
 Pause a running job.
void resume (const JobId &id)
 Resume a paused job.
std::optional< JobSnapshot > snapshot (const JobId &id) const
 Retrieve a job snapshot.
void shutdown ()
 Shut down the job system.

Detailed Description

Definition at line 25 of file JobSystem.h.

Constructor & Destructor Documentation

◆ JobSystem() [1/3]

core::jobs::JobSystem::JobSystem ( std::shared_ptr< core::ports::diagnostics::IErrorReporter > errorReporter,
std::size_t workers = 0 )
explicit

Create a generic job system.

Parameters
errorReporterReporter used for background job diagnostics.
workersWorker count for the scheduler.

Definition at line 55 of file JobSystem.cpp.

Here is the caller graph for this function:

◆ ~JobSystem()

core::jobs::JobSystem::~JobSystem ( )
default

Destroy the job system.

◆ JobSystem() [2/3]

core::jobs::JobSystem::JobSystem ( const JobSystem & )
delete

Copying a job system is disabled.

Here is the call graph for this function:

◆ JobSystem() [3/3]

core::jobs::JobSystem::JobSystem ( JobSystem && other)
defaultnoexcept

Move a job system facade.

Parameters
otherJob system to move from.
Here is the call graph for this function:

Member Function Documentation

◆ cancel()

void core::jobs::JobSystem::cancel ( const JobId & id)

Cancel a job.

Parameters
idJob identifier.

Definition at line 122 of file JobSystem.cpp.

◆ cancelFlag()

std::shared_ptr< std::atomic< bool > > core::jobs::JobSystem::cancelFlag ( const JobId & id) const
nodiscard

Retrieve a job cancellation flag.

Parameters
idJob identifier.
Returns
Shared cancellation flag, or null when the job is unknown.

Definition at line 92 of file JobSystem.cpp.

◆ fail()

void core::jobs::JobSystem::fail ( const JobId & id,
const std::string & error )

Mark a job as failed.

Parameters
idJob identifier.
errorError message to store and publish.

Definition at line 82 of file JobSystem.cpp.

◆ finish()

void core::jobs::JobSystem::finish ( const JobId & id)

Mark a job as finished.

Parameters
idJob identifier.

Definition at line 87 of file JobSystem.cpp.

◆ operator=() [1/2]

JobSystem & core::jobs::JobSystem::operator= ( const JobSystem & )
delete

Copy-assigning a job system is disabled.

Returns
Reference to this job system.
Here is the call graph for this function:

◆ operator=() [2/2]

JobSystem & core::jobs::JobSystem::operator= ( JobSystem && other)
defaultnoexcept

Move-assign a job system facade.

Parameters
otherJob system to move from.
Returns
Reference to this job system.
Here is the call graph for this function:

◆ pause()

void core::jobs::JobSystem::pause ( const JobId & id)

Pause a running job.

Parameters
idJob identifier.

Definition at line 127 of file JobSystem.cpp.

◆ pauseFlag()

std::shared_ptr< std::atomic< bool > > core::jobs::JobSystem::pauseFlag ( const JobId & id) const
nodiscard

Retrieve a job pause flag.

Parameters
idJob identifier.
Returns
Shared pause flag, or null when the job is unknown.

Definition at line 97 of file JobSystem.cpp.

◆ publish()

void core::jobs::JobSystem::publish ( const JobEvent & event)

Publish a job event to subscribers and update its snapshot.

Parameters
eventEvent to publish.

Definition at line 77 of file JobSystem.cpp.

◆ resume()

void core::jobs::JobSystem::resume ( const JobId & id)

Resume a paused job.

Parameters
idJob identifier.

Definition at line 132 of file JobSystem.cpp.

◆ scheduler()

Scheduler & core::jobs::JobSystem::scheduler ( )
nodiscard

Access the shared worker scheduler.

Returns
Scheduler used for background job work.

Definition at line 102 of file JobSystem.cpp.

◆ shutdown()

void core::jobs::JobSystem::shutdown ( )

Shut down the job system.

Definition at line 142 of file JobSystem.cpp.

◆ slotLimiter()

SlotLimiter & core::jobs::JobSystem::slotLimiter ( )
nodiscard

Access the shared slot limiter.

Returns
Slot limiter for scarce external resources.

Definition at line 107 of file JobSystem.cpp.

◆ snapshot()

std::optional< JobSnapshot > core::jobs::JobSystem::snapshot ( const JobId & id) const

Retrieve a job snapshot.

Parameters
idJob identifier.
Returns
Job snapshot, if the job exists.

Definition at line 137 of file JobSystem.cpp.

◆ start()

void core::jobs::JobSystem::start ( const JobId & id)

Mark a job as running.

Parameters
idJob identifier.

Definition at line 72 of file JobSystem.cpp.

◆ submit()

JobId core::jobs::JobSystem::submit ( JobKind kind = JobKind::Generic)
nodiscard

Create a new tracked job.

Parameters
kindKind of job to submit.
Returns
Identifier of the created job.

Definition at line 67 of file JobSystem.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subscribe()

SubscriptionId core::jobs::JobSystem::subscribe ( const JobId & id,
JobEventCallback cb )

Subscribe to job events.

Parameters
idJob identifier.
cbEvent callback.
Returns
Subscription identifier.

Definition at line 112 of file JobSystem.cpp.

◆ unsubscribe()

void core::jobs::JobSystem::unsubscribe ( const JobId & id,
SubscriptionId subId )

Unsubscribe from job events.

Parameters
idJob identifier.
subIdSubscription identifier.

Definition at line 117 of file JobSystem.cpp.


The documentation for this class was generated from the following files: