74 std::function<void(
const common::error_info&)>
on_error;
80 std::optional<retry_policy>
retry;
83 std::optional<std::chrono::milliseconds>
timeout;
170 job(
const std::string& name =
"job");
188 job(
const std::vector<uint8_t>& data,
const std::string& name =
"data_job");
203 [[nodiscard]]
auto get_name(
void)
const -> std::string;
223 [[nodiscard]]
virtual auto do_work(
void) -> common::VoidResult;
290 [[nodiscard]] virtual auto
to_string(
void) const ->
std::
string;
450 [[nodiscard]] auto
get_timeout() const ->
std::optional<
std::chrono::milliseconds>;
548#include <kcenon/thread/utils/formatter_macros.h>
Provides a mechanism for cooperative cancellation of operations.
A thread-safe job queue for managing and dispatching work items.
Represents a unit of work (task) to be executed, typically by a job queue.
auto get_priority() const -> job_priority
Gets the priority level of this job.
std::chrono::steady_clock::time_point enqueue_time_
Time when the job was created.
auto with_retry(const retry_policy &policy) -> job &
Attaches a retry policy to this job.
std::unique_ptr< job_components > components_
Composed components for this job.
virtual auto set_job_queue(const std::shared_ptr< job_queue > &job_queue) -> void
Associates this job with a specific job_queue.
auto ensure_components() -> job_components &
Ensures components_ is allocated (lazy initialization).
auto has_components() const -> bool
Checks if this job has any composed components.
std::vector< uint8_t > data_
An optional container of raw byte data that may be used by the job.
auto with_on_error(std::function< void(const common::error_info &)> callback) -> job &
Attaches an error callback to this job.
std::string name_
The descriptive name of the job, used primarily for identification and logging.
virtual auto set_cancellation_token(const cancellation_token &token) -> void
Sets a cancellation token that can be used to cancel the job.
virtual ~job(void)
Virtual destructor for the job class to allow proper cleanup in derived classes.
virtual auto to_string(void) const -> std::string
Provides a string representation of the job for logging or debugging.
std::uint64_t job_id_
Unique identifier for this job.
static std::atomic< std::uint64_t > next_job_id_
Static counter for generating unique job IDs.
auto with_timeout(std::chrono::milliseconds timeout) -> job &
Sets a timeout for job execution.
auto invoke_callbacks(const common::VoidResult &result) -> void
Invokes the completion callbacks if they are set.
virtual auto get_job_queue(void) const -> std::shared_ptr< job_queue >
Retrieves the job_queue associated with this job, if any.
auto with_priority(job_priority priority) -> job &
Sets the priority level for this job.
auto has_explicit_cancellation() const -> bool
Checks if this job has an explicit cancellation set via composition.
auto get_timeout() const -> std::optional< std::chrono::milliseconds >
Gets the timeout duration for this job.
virtual auto do_work(void) -> common::VoidResult
The core task execution method to be overridden by derived classes.
std::weak_ptr< job_queue > job_queue_
A weak reference to the job_queue that currently manages this job.
auto get_name(void) const -> std::string
Retrieves the name of this job.
cancellation_token cancellation_token_
The cancellation token associated with this job.
auto get_enqueue_time() const -> std::chrono::steady_clock::time_point
Gets the time when this job was created (enqueued).
auto get_job_id() const -> std::uint64_t
Gets the unique ID of this job.
auto with_on_complete(std::function< void(common::VoidResult)> callback) -> job &
Attaches a completion callback to this job.
virtual auto get_cancellation_token() const -> cancellation_token
Gets the cancellation token associated with this job.
auto get_retry_policy() const -> std::optional< retry_policy >
Gets the retry policy of this job.
job(const std::string &name="job")
Constructs a new job with an optional human-readable name.
auto with_cancellation(const cancellation_token &token) -> job &
Attaches a cancellation token to this job via composition.
A template class representing either a value or an error.
Encapsulates retry behavior configuration for jobs.
@ low
Between low and high watermark.
@ high
Above high_watermark, approaching capacity.
@ callback
Call user callback for custom decision.
Implementation of a cancellation token for cooperative cancellation.
Error codes and utilities for the thread system.
String encoding conversion, Base64 encoding/decoding utilities.
Core threading foundation of the thread system library.
job_priority
Priority levels for job scheduling.
@ lowest
Lowest priority, executed when no other jobs are pending.
@ realtime
Real-time priority, should be used sparingly.
@ highest
Highest priority, critical tasks.
@ normal
Normal priority, default for most jobs.
@ priority
Priority-based scheduling.
Retry policy with configurable strategies: fixed, linear, and exponential backoff.
Internal structure holding composed behaviors for a job.
std::optional< job_priority > priority
Optional priority override for this job.
bool has_explicit_cancellation
Flag indicating explicit cancellation token was set via composition.
std::function< void(const common::error_info &)> on_error
Callback invoked specifically on error.
std::optional< std::chrono::milliseconds > timeout
Optional timeout for job execution.
std::function< void(common::VoidResult)> on_complete
Callback invoked when job completes (success or error)
std::optional< retry_policy > retry
Retry policy for automatic retry on failure.