|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Fluent builder for creating and configuring jobs with composition. More...
#include <job_builder.h>

Classes | |
| class | built_job |
| Internal job implementation created by the builder. More... | |
Public Member Functions | |
| job_builder ()=default | |
| Default constructor. | |
| auto | name (const std::string &name) -> job_builder & |
| Sets the job name. | |
| auto | work (std::function< common::VoidResult()> work_fn) -> job_builder & |
| Sets the work function for the job. | |
| auto | work_with_data (const std::vector< uint8_t > &data, std::function< common::VoidResult(const std::vector< uint8_t > &)> work_fn) -> job_builder & |
| Sets the work function with data parameter. | |
| auto | cancellation (const cancellation_token &token) -> job_builder & |
| Sets a cancellation token for cooperative cancellation. | |
| auto | on_complete (std::function< void(common::VoidResult)> callback) -> job_builder & |
| Sets a completion callback. | |
| auto | on_error (std::function< void(const common::error_info &)> callback) -> job_builder & |
| Sets an error callback. | |
| auto | priority (job_priority prio) -> job_builder & |
| Sets the job priority. | |
| auto | retry (const retry_policy &policy) -> job_builder & |
| Sets the retry policy. | |
| auto | timeout (std::chrono::milliseconds timeout) -> job_builder & |
| Sets the execution timeout. | |
| template<typename JobType , typename... Args> | |
| auto | from (Args &&... args) -> job_builder & |
| auto | build () -> std::unique_ptr< job > |
| Builds and returns the configured job. | |
| auto | build_shared () -> std::shared_ptr< job > |
| Builds and returns the configured job as a shared pointer. | |
Private Attributes | |
| std::string | name_ |
| std::vector< uint8_t > | data_ |
| std::function< common::VoidResult()> | work_fn_ |
| std::function< common::VoidResult(const std::vector< uint8_t > &)> | data_work_fn_ |
| cancellation_token | cancellation_token_ |
| bool | has_cancellation_ {false} |
| std::function< void(common::VoidResult)> | on_complete_ |
| std::function< void(const common::error_info &)> | on_error_ |
| job_priority | priority_ {job_priority::normal} |
| bool | has_priority_ {false} |
| retry_policy | retry_policy_ |
| bool | has_retry_ {false} |
| std::chrono::milliseconds | timeout_ {0} |
| bool | has_timeout_ {false} |
| std::function< std::unique_ptr< job >()> | custom_job_factory_ |
| bool | use_custom_job_ {false} |
Fluent builder for creating and configuring jobs with composition.
The job_builder class provides a clean, fluent interface for creating jobs with various behaviors composed together.
Instead of inheritance-based specialization:
Use composition via the builder:
Definition at line 97 of file job_builder.h.
|
default |
Default constructor.
|
inlinenodiscard |
Builds and returns the configured job.
Definition at line 271 of file job_builder.h.
References cancellation_token_, custom_job_factory_, data_, data_work_fn_, has_cancellation_, has_priority_, has_retry_, has_timeout_, name_, on_complete_, on_error_, priority_, retry_policy_, timeout_, use_custom_job_, and work_fn_.
Referenced by build_shared().

|
inlinenodiscard |
Builds and returns the configured job as a shared pointer.
Definition at line 323 of file job_builder.h.
References build().

|
inline |
Sets a cancellation token for cooperative cancellation.
| token | Cancellation token to use |
Definition at line 153 of file job_builder.h.
References cancellation_token_, and has_cancellation_.
|
inline |
Definition at line 248 of file job_builder.h.
References custom_job_factory_, and use_custom_job_.
|
inline |
Sets the job name.
| name | Descriptive name for the job |
Definition at line 110 of file job_builder.h.
Referenced by name().


|
inline |
Sets a completion callback.
| callback | Function called when job completes (success or failure) |
Definition at line 166 of file job_builder.h.
References kcenon::thread::callback, and on_complete_.
|
inline |
Sets an error callback.
| callback | Function called only when job fails |
Definition at line 178 of file job_builder.h.
References kcenon::thread::callback, and on_error_.
|
inline |
Sets the job priority.
| prio | Priority level for scheduling |
Definition at line 190 of file job_builder.h.
References has_priority_, and priority_.
|
inline |
Sets the retry policy.
| policy | Retry behavior configuration |
Definition at line 203 of file job_builder.h.
References has_retry_, and retry_policy_.
|
inline |
Sets the execution timeout.
| timeout | Maximum execution time allowed |
Definition at line 216 of file job_builder.h.
References has_timeout_, timeout(), and timeout_.
Referenced by timeout().


|
inline |
Sets the work function for the job.
| work_fn | Function that performs the job's work |
Definition at line 125 of file job_builder.h.
References work_fn_.
|
inline |
Sets the work function with data parameter.
| data | Binary data to pass to the work function |
| work_fn | Function that processes the data |
Definition at line 138 of file job_builder.h.
References data_, and data_work_fn_.
|
private |
Definition at line 400 of file job_builder.h.
Referenced by build(), and cancellation().
|
private |
Definition at line 415 of file job_builder.h.
|
private |
Definition at line 396 of file job_builder.h.
Referenced by build(), and work_with_data().
|
private |
Definition at line 398 of file job_builder.h.
Referenced by build(), and work_with_data().
|
private |
Definition at line 401 of file job_builder.h.
Referenced by build(), and cancellation().
|
private |
|
private |
Definition at line 410 of file job_builder.h.
|
private |
Definition at line 413 of file job_builder.h.
|
private |
Definition at line 395 of file job_builder.h.
|
private |
Definition at line 403 of file job_builder.h.
Referenced by build(), and on_complete().
|
private |
Definition at line 404 of file job_builder.h.
Referenced by build(), and on_error().
|
private |
Definition at line 406 of file job_builder.h.
Referenced by build(), and priority().
|
private |
Definition at line 409 of file job_builder.h.
|
private |
Definition at line 412 of file job_builder.h.
|
private |
Definition at line 416 of file job_builder.h.
|
private |
Definition at line 397 of file job_builder.h.