139 const std::vector<uint8_t>& data,
140 std::function<common::VoidResult(
const std::vector<uint8_t>&)> work_fn) ->
job_builder&
247 template<
typename JobType,
typename... Args>
250 static_assert(std::is_base_of_v<job, JobType>,
251 "JobType must be derived from kcenon::thread::job");
255 return std::apply([](
auto&&... a) {
256 return std::make_unique<JobType>(std::forward<
decltype(a)>(a)...);
271 [[nodiscard]]
auto build() -> std::unique_ptr<job>
273 std::unique_ptr<job>
result;
281 result = std::make_unique<built_job>(
340 const std::string&
name,
341 const std::vector<uint8_t>& data,
342 std::function<common::VoidResult()> work_fn,
343 std::function<common::VoidResult(
const std::vector<uint8_t>&)> data_work_fn)
354 [[nodiscard]]
auto do_work() -> common::VoidResult
override
364 common::VoidResult
result = [
this]() -> common::VoidResult {
375 return common::error_info{
377 "No work function provided to job_builder",
391 std::function<common::VoidResult(
const std::vector<uint8_t>&)>
data_work_fn_;
398 std::function<common::VoidResult(
const std::vector<uint8_t>&)>
data_work_fn_;
404 std::function<void(
const common::error_info&)>
on_error_;
Provides a mechanism for cooperative cancellation of operations.
bool is_cancelled() const
Checks if the token has been canceled.
Internal job implementation created by the builder.
std::function< common::VoidResult()> work_fn_
auto do_work() -> common::VoidResult override
The core task execution method to be overridden by derived classes.
std::function< common::VoidResult(const std::vector< uint8_t > &)> data_work_fn_
built_job(const std::string &name, const std::vector< uint8_t > &data, std::function< common::VoidResult()> work_fn, std::function< common::VoidResult(const std::vector< uint8_t > &)> data_work_fn)
Fluent builder for creating and configuring jobs with composition.
auto work(std::function< common::VoidResult()> work_fn) -> job_builder &
Sets the work function for the job.
cancellation_token cancellation_token_
auto cancellation(const cancellation_token &token) -> job_builder &
Sets a cancellation token for cooperative cancellation.
std::function< common::VoidResult()> work_fn_
job_builder()=default
Default constructor.
auto build_shared() -> std::shared_ptr< job >
Builds and returns the configured job as a shared pointer.
std::vector< uint8_t > data_
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 priority(job_priority prio) -> job_builder &
Sets the job priority.
auto on_error(std::function< void(const common::error_info &)> callback) -> job_builder &
Sets an error callback.
auto on_complete(std::function< void(common::VoidResult)> callback) -> job_builder &
Sets a completion callback.
auto build() -> std::unique_ptr< job >
Builds and returns the configured job.
auto from(Args &&... args) -> job_builder &
auto timeout(std::chrono::milliseconds timeout) -> job_builder &
Sets the execution timeout.
std::function< void(const common::error_info &)> on_error_
std::function< std::unique_ptr< job >()> custom_job_factory_
auto retry(const retry_policy &policy) -> job_builder &
Sets the retry policy.
std::chrono::milliseconds timeout_
auto name(const std::string &name) -> job_builder &
Sets the job name.
std::function< void(common::VoidResult)> on_complete_
retry_policy retry_policy_
std::function< common::VoidResult(const std::vector< uint8_t > &)> data_work_fn_
Represents a unit of work (task) to be executed, typically by a job queue.
std::vector< uint8_t > data_
An optional container of raw byte data that may be used by the job.
auto invoke_callbacks(const common::VoidResult &result) -> void
Invokes the completion callbacks if they are set.
cancellation_token cancellation_token_
The cancellation token associated with this job.
A template class representing either a value or an error.
Encapsulates retry behavior configuration for jobs.
@ callback
Call user callback for custom decision.
Implementation of a cancellation token for cooperative cancellation.
Base job class for schedulable work units in the thread system.
Core threading foundation of the thread system library.
auto make_job() -> job_builder
common::VoidResult make_error_result(error_code code, const std::string &message="")
Create a common::VoidResult error from a thread::error_code.
job_priority
Priority levels for job scheduling.
@ normal
Normal priority, default for most jobs.
Retry policy with configurable strategies: fixed, linear, and exponential backoff.