|
PACS System 0.1.0
PACS DICOM system library
|
#include <task_scheduler.h>

Public Member Functions | |
| task_scheduler (storage::index_database &database, const task_scheduler_config &config={}) | |
| Construct task scheduler. | |
| task_scheduler (storage::index_database &database, storage::file_storage &file_storage, std::shared_ptr< kcenon::thread::thread_pool > thread_pool, const task_scheduler_config &config={}) | |
| Construct task scheduler with storage and thread pool. | |
| task_scheduler (storage::index_database &database, storage::file_storage &file_storage, std::shared_ptr< kcenon::common::interfaces::IExecutor > executor, const task_scheduler_config &config={}) | |
| Construct task scheduler with IExecutor (recommended) | |
| ~task_scheduler () | |
| Destructor - ensures graceful shutdown. | |
| task_scheduler (const task_scheduler &)=delete | |
| Non-copyable. | |
| task_scheduler & | operator= (const task_scheduler &)=delete |
| task_scheduler (task_scheduler &&)=delete | |
| Non-movable. | |
| task_scheduler & | operator= (task_scheduler &&)=delete |
| void | start () |
| Start the scheduler service. | |
| void | stop (bool wait_for_completion=true) |
| Stop the scheduler service. | |
| auto | is_running () const noexcept -> bool |
| Check if the scheduler is running. | |
| auto | schedule_cleanup (const cleanup_config &config) -> task_id |
| Schedule cleanup task. | |
| auto | schedule_archive (const archive_config &config) -> task_id |
| Schedule archive task. | |
| auto | schedule_verification (const verification_config &config) -> task_id |
| Schedule verification task. | |
| auto | schedule (const std::string &name, const std::string &description, std::chrono::seconds interval, task_callback_with_result callback) -> task_id |
| Schedule a custom task with interval. | |
| auto | schedule (const std::string &name, const std::string &description, const cron_schedule &cron_expr, task_callback_with_result callback) -> task_id |
| Schedule a custom task with cron schedule. | |
| auto | schedule_once (const std::string &name, const std::string &description, std::chrono::system_clock::time_point execute_at, task_callback_with_result callback) -> task_id |
| Schedule a one-time task. | |
| auto | schedule (scheduled_task task) -> task_id |
| Schedule a task with full definition. | |
| auto | list_tasks () const -> std::vector< scheduled_task > |
| List all scheduled tasks. | |
| auto | list_tasks (task_type type) const -> std::vector< scheduled_task > |
| List tasks by type. | |
| auto | list_tasks (task_state state) const -> std::vector< scheduled_task > |
| List tasks by state. | |
| auto | get_task (const task_id &id) const -> std::optional< scheduled_task > |
| Get a specific task by ID. | |
| auto | cancel_task (const task_id &id) -> bool |
| Cancel a scheduled task. | |
| auto | pause_task (const task_id &id) -> bool |
| Pause a scheduled task. | |
| auto | resume_task (const task_id &id) -> bool |
| Resume a paused task. | |
| auto | trigger_task (const task_id &id) -> bool |
| Trigger immediate execution of a task. | |
| auto | update_schedule (const task_id &id, const kcenon::pacs::workflow::schedule &new_schedule) -> bool |
| Update task schedule. | |
| auto | get_execution_history (const task_id &id, std::size_t limit=100) const -> std::vector< task_execution_record > |
| Get execution history for a task. | |
| auto | get_recent_executions (std::size_t limit=100) const -> std::vector< task_execution_record > |
| Get all recent executions. | |
| void | clear_history (const task_id &id, std::size_t keep_last=0) |
| Clear execution history for a task. | |
| auto | get_stats () const -> scheduler_stats |
| Get scheduler statistics. | |
| auto | pending_count () const noexcept -> std::size_t |
| Get number of pending tasks. | |
| auto | running_count () const noexcept -> std::size_t |
| Get number of running tasks. | |
| auto | save_tasks () const -> bool |
| Save all tasks to persistence storage. | |
| auto | load_tasks () -> std::size_t |
| Load tasks from persistence storage. | |
| void | set_task_complete_callback (task_scheduler_config::task_complete_callback callback) |
| Set the task complete callback. | |
| void | set_error_callback (task_scheduler_config::task_error_callback callback) |
| Set the error callback. | |
Private Member Functions | |
| void | run_loop () |
| Background thread main loop. | |
| void | execute_cycle () |
| Execute a single scheduler cycle. | |
| auto | execute_task (scheduled_task &task) -> task_execution_record |
| Execute a single task. | |
| auto | calculate_next_run (const kcenon::pacs::workflow::schedule &sched, std::chrono::system_clock::time_point from=std::chrono::system_clock::now()) const -> std::optional< std::chrono::system_clock::time_point > |
| Calculate next run time for a schedule. | |
| auto | calculate_next_cron_run (const cron_schedule &cron, std::chrono::system_clock::time_point from) const -> std::optional< std::chrono::system_clock::time_point > |
| Calculate next run time for cron schedule. | |
| auto | generate_task_id () const -> task_id |
| Generate unique task ID. | |
| auto | generate_execution_id () const -> std::string |
| Generate unique execution ID. | |
| auto | create_cleanup_callback (const cleanup_config &config) -> task_callback_with_result |
| Create cleanup task callback. | |
| auto | create_archive_callback (const archive_config &config) -> task_callback_with_result |
| Create archive task callback. | |
| auto | create_verification_callback (const verification_config &config) -> task_callback_with_result |
| Create verification task callback. | |
| void | record_execution (const task_id &task_id, const task_execution_record &record) |
| Record task execution. | |
| void | update_stats (const task_execution_record &record) |
| Update statistics after execution. | |
| auto | serialize_tasks () const -> std::string |
| Serialize tasks to JSON. | |
| auto | deserialize_tasks (const std::string &json) -> std::size_t |
| Deserialize tasks from JSON. | |
Private Attributes | |
| storage::index_database & | database_ |
| Reference to PACS index database. | |
| storage::file_storage * | file_storage_ {nullptr} |
| Optional reference to file storage. | |
| std::shared_ptr< kcenon::thread::thread_pool > | thread_pool_ |
| Thread pool for parallel task execution (legacy) | |
| std::shared_ptr< kcenon::common::interfaces::IExecutor > | executor_ |
| IExecutor for task execution (recommended, Issue #487) | |
| task_scheduler_config | config_ |
| Service configuration. | |
| std::thread | scheduler_thread_ |
| Background scheduler thread. | |
| std::mutex | mutex_ |
| Mutex for thread synchronization. | |
| std::condition_variable | cv_ |
| Condition variable for sleep/wake. | |
| std::atomic< bool > | stop_requested_ {false} |
| Flag to signal shutdown. | |
| std::atomic< bool > | running_ {false} |
| Flag indicating scheduler is running. | |
| std::map< task_id, scheduled_task > | tasks_ |
| All scheduled tasks (id -> task) | |
| std::mutex | tasks_mutex_ |
| Mutex for tasks map. | |
| std::map< task_id, std::vector< task_execution_record > > | execution_history_ |
| Execution history (task_id -> records) | |
| std::mutex | history_mutex_ |
| Mutex for execution history. | |
| std::atomic< std::size_t > | running_count_ {0} |
| Running task count. | |
| scheduler_stats | stats_ |
| Scheduler statistics. | |
| std::mutex | stats_mutex_ |
| Mutex for statistics. | |
| std::chrono::steady_clock::time_point | start_time_ |
| Start time for uptime calculation. | |
| std::atomic< uint64_t > | next_task_id_ {1} |
| Next task ID counter. | |
| std::atomic< uint64_t > | next_execution_id_ {1} |
| Next execution ID counter. | |
Definition at line 162 of file task_scheduler.h.
|
explicit |
Construct task scheduler.
| database | Reference to the PACS index database |
| config | Service configuration |
Definition at line 68 of file task_scheduler.cpp.
References kcenon::pacs::workflow::task_scheduler_config::archive, kcenon::pacs::workflow::task_scheduler_config::auto_start, kcenon::pacs::workflow::task_scheduler_config::cleanup, config_, kcenon::pacs::workflow::task_scheduler_config::enabled, if(), and kcenon::pacs::workflow::task_scheduler_config::verification.

| kcenon::pacs::workflow::task_scheduler::task_scheduler | ( | storage::index_database & | database, |
| storage::file_storage & | file_storage, | ||
| std::shared_ptr< kcenon::thread::thread_pool > | thread_pool, | ||
| const task_scheduler_config & | config = {} ) |
Construct task scheduler with storage and thread pool.
| database | Reference to the PACS index database |
| file_storage | Reference to file storage for cleanup/archive |
| thread_pool | Thread pool for parallel task execution |
| config | Service configuration |
Definition at line 89 of file task_scheduler.cpp.
References kcenon::pacs::workflow::task_scheduler_config::archive, kcenon::pacs::workflow::task_scheduler_config::auto_start, kcenon::pacs::workflow::task_scheduler_config::cleanup, config_, kcenon::pacs::workflow::task_scheduler_config::enabled, if(), kcenon::pacs::workflow::task_scheduler_config::persistence_path, kcenon::pacs::workflow::task_scheduler_config::restore_on_startup, and kcenon::pacs::workflow::task_scheduler_config::verification.

| kcenon::pacs::workflow::task_scheduler::task_scheduler | ( | storage::index_database & | database, |
| storage::file_storage & | file_storage, | ||
| std::shared_ptr< kcenon::common::interfaces::IExecutor > | executor, | ||
| const task_scheduler_config & | config = {} ) |
Construct task scheduler with IExecutor (recommended)
This constructor accepts the standardized IExecutor interface from common_system, enabling better testability and decoupling from specific thread pool implementations.
| database | Reference to the PACS index database |
| file_storage | Reference to file storage for cleanup/archive |
| executor | IExecutor for task execution (from common_system) |
| config | Service configuration |
Definition at line 120 of file task_scheduler.cpp.
References kcenon::pacs::workflow::task_scheduler_config::archive, kcenon::pacs::workflow::task_scheduler_config::auto_start, kcenon::pacs::workflow::task_scheduler_config::cleanup, config_, kcenon::pacs::workflow::task_scheduler_config::enabled, if(), kcenon::pacs::workflow::task_scheduler_config::persistence_path, kcenon::pacs::workflow::task_scheduler_config::restore_on_startup, and kcenon::pacs::workflow::task_scheduler_config::verification.

| kcenon::pacs::workflow::task_scheduler::~task_scheduler | ( | ) |
Destructor - ensures graceful shutdown.
Definition at line 151 of file task_scheduler.cpp.
References config_, kcenon::pacs::workflow::task_scheduler_config::persistence_path, save_tasks(), and stop().

|
delete |
Non-copyable.
|
delete |
Non-movable.
|
nodiscardprivate |
Calculate next run time for cron schedule.
| cron | Cron schedule |
| from | Starting time point |
Definition at line 1022 of file task_scheduler.cpp.
|
nodiscardprivate |
Calculate next run time for a schedule.
| sched | Schedule definition |
| from | Starting time point |
Definition at line 995 of file task_scheduler.cpp.
Referenced by execute_cycle().

| auto kcenon::pacs::workflow::task_scheduler::cancel_task | ( | const task_id & | id | ) | -> bool |
Cancel a scheduled task.
Removes the task from the schedule. If the task is currently running, it will complete but not be rescheduled.
| id | Task ID to cancel |
Definition at line 428 of file task_scheduler.cpp.
References kcenon::pacs::workflow::cancelled, and kcenon::pacs::integration::logger_adapter::info().

| void kcenon::pacs::workflow::task_scheduler::clear_history | ( | const task_id & | id, |
| std::size_t | keep_last = 0 ) |
Clear execution history for a task.
| id | Task ID |
| keep_last | Number of records to keep |
Definition at line 585 of file task_scheduler.cpp.
References execution_history_, and history_mutex_.
|
nodiscardprivate |
Create archive task callback.
| config | Archive configuration |
Definition at line 1224 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), kcenon::pacs::integration::logger_adapter::info(), and kcenon::pacs::integration::logger_adapter::warn().

|
nodiscardprivate |
Create cleanup task callback.
| config | Cleanup configuration |
Definition at line 1108 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), kcenon::pacs::integration::logger_adapter::info(), and kcenon::pacs::integration::logger_adapter::warn().

|
nodiscardprivate |
Create verification task callback.
| config | Verification configuration |
Definition at line 1356 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), kcenon::pacs::integration::logger_adapter::info(), and kcenon::pacs::integration::logger_adapter::warn().

|
private |
Deserialize tasks from JSON.
| json | JSON string |
Definition at line 1554 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::warn().

|
private |
Execute a single scheduler cycle.
Checks for due tasks and executes them.
Definition at line 755 of file task_scheduler.cpp.
References calculate_next_run(), kcenon::pacs::workflow::completed, config_, execute_task(), kcenon::pacs::workflow::failed, kcenon::pacs::integration::monitoring_adapter::increment_counter(), kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::workflow::scheduler_stats::last_cycle_at, kcenon::pacs::workflow::task_scheduler_config::max_concurrent_tasks, kcenon::pacs::workflow::task_scheduler_config::on_cycle_complete, kcenon::pacs::workflow::task_scheduler_config::on_task_complete, kcenon::pacs::workflow::task_scheduler_config::on_task_error, kcenon::pacs::workflow::pending, record_execution(), kcenon::pacs::workflow::running, running_count_, stats_, stats_mutex_, tasks_, tasks_mutex_, and update_stats().
Referenced by run_loop().


|
private |
Execute a single task.
| task | Task to execute |
Definition at line 882 of file task_scheduler.cpp.
References kcenon::pacs::workflow::completed, kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), kcenon::pacs::workflow::failed, kcenon::pacs::integration::monitoring_adapter::increment_counter(), kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::integration::monitoring_adapter::record_histogram(), kcenon::pacs::workflow::running, and kcenon::pacs::integration::logger_adapter::warn().
Referenced by execute_cycle().


|
nodiscardprivate |
Generate unique execution ID.
Definition at line 1097 of file task_scheduler.cpp.
References next_execution_id_.
|
nodiscardprivate |
Generate unique task ID.
Definition at line 1092 of file task_scheduler.cpp.
References next_task_id_.
|
nodiscard |
Get execution history for a task.
| id | Task ID |
| limit | Maximum number of records to return |
Definition at line 541 of file task_scheduler.cpp.
|
nodiscard |
Get all recent executions.
| limit | Maximum number of records to return |
Definition at line 562 of file task_scheduler.cpp.
|
nodiscard |
Get scheduler statistics.
Definition at line 608 of file task_scheduler.cpp.
References running_, running_count_, kcenon::pacs::workflow::scheduler_stats::running_tasks, kcenon::pacs::workflow::scheduler_stats::scheduled_tasks, start_time_, stats_, stats_mutex_, tasks_, tasks_mutex_, and kcenon::pacs::workflow::scheduler_stats::uptime.
|
nodiscard |
Get a specific task by ID.
| id | Task ID |
Definition at line 416 of file task_scheduler.cpp.
|
nodiscardnoexcept |
Check if the scheduler is running.
Definition at line 201 of file task_scheduler.cpp.
References running_.
|
nodiscard |
List all scheduled tasks.
Definition at line 373 of file task_scheduler.cpp.
References tasks_, and tasks_mutex_.
|
nodiscard |
List tasks by state.
| state | Task state to filter by |
Definition at line 401 of file task_scheduler.cpp.
|
nodiscard |
List tasks by type.
| type | Task type to filter by |
Definition at line 386 of file task_scheduler.cpp.
| auto kcenon::pacs::workflow::task_scheduler::load_tasks | ( | ) | -> std::size_t |
Load tasks from persistence storage.
Definition at line 681 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), and kcenon::pacs::integration::logger_adapter::info().

|
delete |
|
delete |
| auto kcenon::pacs::workflow::task_scheduler::pause_task | ( | const task_id & | id | ) | -> bool |
Pause a scheduled task.
Temporarily suspends task execution. The task remains scheduled but will not execute until resumed.
| id | Task ID to pause |
Definition at line 447 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::workflow::paused, and kcenon::pacs::workflow::running.

|
nodiscardnoexcept |
Get number of pending tasks.
Definition at line 630 of file task_scheduler.cpp.
References kcenon::pacs::workflow::pending, tasks_, and tasks_mutex_.
|
private |
Record task execution.
| task_id | Task ID |
| record | Execution record |
Definition at line 1475 of file task_scheduler.cpp.
References execution_history_, and history_mutex_.
Referenced by execute_cycle().

| auto kcenon::pacs::workflow::task_scheduler::resume_task | ( | const task_id & | id | ) | -> bool |
Resume a paused task.
| id | Task ID to resume |
Definition at line 469 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::workflow::paused, and kcenon::pacs::workflow::pending.

|
private |
Background thread main loop.
Definition at line 733 of file task_scheduler.cpp.
References kcenon::pacs::workflow::task_scheduler_config::check_interval, config_, cv_, kcenon::pacs::integration::logger_adapter::debug(), execute_cycle(), mutex_, and stop_requested_.
Referenced by start().


|
nodiscardnoexcept |
Get number of running tasks.
Definition at line 642 of file task_scheduler.cpp.
References running_count_.
| auto kcenon::pacs::workflow::task_scheduler::save_tasks | ( | ) | const -> bool |
Save all tasks to persistence storage.
Definition at line 650 of file task_scheduler.cpp.
References config_, kcenon::pacs::integration::logger_adapter::debug(), kcenon::pacs::integration::logger_adapter::error(), kcenon::pacs::workflow::task_scheduler_config::persistence_path, and serialize_tasks().
Referenced by ~task_scheduler().


| auto kcenon::pacs::workflow::task_scheduler::schedule | ( | const std::string & | name, |
| const std::string & | description, | ||
| const cron_schedule & | cron_expr, | ||
| task_callback_with_result | callback ) -> task_id |
Schedule a custom task with cron schedule.
| name | Task name |
| description | Task description |
| cron_expr | Cron schedule expression |
| callback | Task callback function |
Definition at line 293 of file task_scheduler.cpp.
References kcenon::pacs::workflow::scheduled_task::callback, kcenon::pacs::workflow::scheduled_task::created_at, kcenon::pacs::workflow::custom, kcenon::pacs::workflow::scheduled_task::description, kcenon::pacs::workflow::scheduled_task::enabled, kcenon::pacs::workflow::scheduled_task::id, kcenon::pacs::workflow::scheduled_task::name, name, kcenon::pacs::workflow::scheduled_task::task_schedule, kcenon::pacs::workflow::scheduled_task::type, and kcenon::pacs::workflow::scheduled_task::updated_at.
| auto kcenon::pacs::workflow::task_scheduler::schedule | ( | const std::string & | name, |
| const std::string & | description, | ||
| std::chrono::seconds | interval, | ||
| task_callback_with_result | callback ) -> task_id |
Schedule a custom task with interval.
| name | Task name |
| description | Task description |
| interval | Interval between executions |
| callback | Task callback function |
Definition at line 273 of file task_scheduler.cpp.
References kcenon::pacs::workflow::scheduled_task::callback, kcenon::pacs::workflow::scheduled_task::created_at, kcenon::pacs::workflow::custom, kcenon::pacs::workflow::scheduled_task::description, kcenon::pacs::workflow::scheduled_task::enabled, kcenon::pacs::workflow::scheduled_task::id, kcenon::pacs::workflow::scheduled_task::name, name, kcenon::pacs::workflow::scheduled_task::task_schedule, kcenon::pacs::workflow::scheduled_task::type, and kcenon::pacs::workflow::scheduled_task::updated_at.
| auto kcenon::pacs::workflow::task_scheduler::schedule | ( | scheduled_task | task | ) | -> task_id |
Schedule a task with full definition.
| task | Complete task definition |
Definition at line 334 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::info(), and name.

| auto kcenon::pacs::workflow::task_scheduler::schedule_archive | ( | const archive_config & | config | ) | -> task_id |
Schedule archive task.
Creates an archive task with the specified configuration. If an archive task already exists, updates its configuration.
| config | Archive configuration |
Definition at line 230 of file task_scheduler.cpp.
References kcenon::pacs::workflow::archive, kcenon::pacs::workflow::scheduled_task::callback, kcenon::pacs::workflow::scheduled_task::created_at, kcenon::pacs::workflow::scheduled_task::description, kcenon::pacs::workflow::scheduled_task::enabled, kcenon::pacs::workflow::scheduled_task::id, kcenon::pacs::workflow::scheduled_task::name, kcenon::pacs::workflow::scheduled_task::priority, kcenon::pacs::workflow::scheduled_task::tags, kcenon::pacs::workflow::scheduled_task::task_schedule, kcenon::pacs::workflow::scheduled_task::type, and kcenon::pacs::workflow::scheduled_task::updated_at.
| auto kcenon::pacs::workflow::task_scheduler::schedule_cleanup | ( | const cleanup_config & | config | ) | -> task_id |
Schedule cleanup task.
Creates a cleanup task with the specified configuration. If a cleanup task already exists, updates its configuration.
| config | Cleanup configuration |
Definition at line 209 of file task_scheduler.cpp.
References kcenon::pacs::workflow::scheduled_task::callback, kcenon::pacs::workflow::cleanup, kcenon::pacs::workflow::scheduled_task::created_at, kcenon::pacs::workflow::scheduled_task::description, kcenon::pacs::workflow::scheduled_task::enabled, kcenon::pacs::workflow::scheduled_task::id, kcenon::pacs::workflow::scheduled_task::name, kcenon::pacs::workflow::scheduled_task::priority, kcenon::pacs::workflow::scheduled_task::tags, kcenon::pacs::workflow::scheduled_task::task_schedule, kcenon::pacs::workflow::scheduled_task::type, and kcenon::pacs::workflow::scheduled_task::updated_at.
| auto kcenon::pacs::workflow::task_scheduler::schedule_once | ( | const std::string & | name, |
| const std::string & | description, | ||
| std::chrono::system_clock::time_point | execute_at, | ||
| task_callback_with_result | callback ) -> task_id |
Schedule a one-time task.
| name | Task name |
| description | Task description |
| execute_at | Execution time |
| callback | Task callback function |
Definition at line 313 of file task_scheduler.cpp.
References kcenon::pacs::workflow::scheduled_task::callback, kcenon::pacs::workflow::scheduled_task::created_at, kcenon::pacs::workflow::custom, kcenon::pacs::workflow::scheduled_task::description, kcenon::pacs::workflow::scheduled_task::enabled, kcenon::pacs::workflow::scheduled_task::id, kcenon::pacs::workflow::scheduled_task::name, name, kcenon::pacs::workflow::scheduled_task::next_run_at, kcenon::pacs::workflow::scheduled_task::task_schedule, kcenon::pacs::workflow::scheduled_task::type, and kcenon::pacs::workflow::scheduled_task::updated_at.
| auto kcenon::pacs::workflow::task_scheduler::schedule_verification | ( | const verification_config & | config | ) | -> task_id |
Schedule verification task.
Creates a verification task with the specified configuration. If a verification task already exists, updates its configuration.
| config | Verification configuration |
Definition at line 251 of file task_scheduler.cpp.
References kcenon::pacs::workflow::scheduled_task::callback, kcenon::pacs::workflow::scheduled_task::created_at, kcenon::pacs::workflow::scheduled_task::description, kcenon::pacs::workflow::scheduled_task::enabled, kcenon::pacs::workflow::scheduled_task::id, kcenon::pacs::workflow::scheduled_task::name, kcenon::pacs::workflow::scheduled_task::priority, kcenon::pacs::workflow::scheduled_task::tags, kcenon::pacs::workflow::scheduled_task::task_schedule, kcenon::pacs::workflow::scheduled_task::type, kcenon::pacs::workflow::scheduled_task::updated_at, and kcenon::pacs::workflow::verification.
|
nodiscardprivate |
Serialize tasks to JSON.
Definition at line 1526 of file task_scheduler.cpp.
References tasks_, tasks_mutex_, and kcenon::pacs::workflow::to_string().
Referenced by save_tasks().


| void kcenon::pacs::workflow::task_scheduler::set_error_callback | ( | task_scheduler_config::task_error_callback | callback | ) |
Set the error callback.
| callback | Function called when a task fails |
Definition at line 723 of file task_scheduler.cpp.
References config_, mutex_, and kcenon::pacs::workflow::task_scheduler_config::on_task_error.
| void kcenon::pacs::workflow::task_scheduler::set_task_complete_callback | ( | task_scheduler_config::task_complete_callback | callback | ) |
Set the task complete callback.
| callback | Function called after each task execution |
Definition at line 717 of file task_scheduler.cpp.
References config_, mutex_, and kcenon::pacs::workflow::task_scheduler_config::on_task_complete.
| void kcenon::pacs::workflow::task_scheduler::start | ( | ) |
Start the scheduler service.
Starts the background scheduler thread and begins monitoring for tasks to execute.
Definition at line 164 of file task_scheduler.cpp.
References kcenon::pacs::workflow::task_scheduler_config::check_interval, config_, kcenon::pacs::integration::logger_adapter::info(), kcenon::pacs::workflow::task_scheduler_config::max_concurrent_tasks, run_loop(), running_, scheduler_thread_, start_time_, and stop_requested_.

| void kcenon::pacs::workflow::task_scheduler::stop | ( | bool | wait_for_completion = true | ) |
Stop the scheduler service.
Gracefully stops the service, waiting for any in-progress tasks to complete.
| wait_for_completion | If true, waits for running tasks |
Definition at line 182 of file task_scheduler.cpp.
References cv_, kcenon::pacs::integration::logger_adapter::info(), running_, scheduler_thread_, and stop_requested_.
Referenced by ~task_scheduler().


| auto kcenon::pacs::workflow::task_scheduler::trigger_task | ( | const task_id & | id | ) | -> bool |
Trigger immediate execution of a task.
Executes the task immediately, regardless of its schedule.
| id | Task ID to execute |
Definition at line 492 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::info(), and kcenon::pacs::workflow::running.

| auto kcenon::pacs::workflow::task_scheduler::update_schedule | ( | const task_id & | id, |
| const kcenon::pacs::workflow::schedule & | new_schedule ) -> bool |
Update task schedule.
| id | Task ID |
| new_schedule | New schedule |
Definition at line 517 of file task_scheduler.cpp.
References kcenon::pacs::integration::logger_adapter::info().

|
private |
Update statistics after execution.
| record | Execution record |
Definition at line 1491 of file task_scheduler.cpp.
References kcenon::pacs::workflow::scheduler_stats::avg_execution_time, kcenon::pacs::workflow::cancelled, kcenon::pacs::workflow::scheduler_stats::cancelled_executions, kcenon::pacs::workflow::completed, kcenon::pacs::workflow::failed, kcenon::pacs::workflow::scheduler_stats::failed_executions, kcenon::pacs::workflow::scheduler_stats::max_execution_time, stats_, stats_mutex_, kcenon::pacs::workflow::scheduler_stats::successful_executions, and kcenon::pacs::workflow::scheduler_stats::total_executions.
Referenced by execute_cycle().

|
private |
Service configuration.
Definition at line 677 of file task_scheduler.h.
Referenced by execute_cycle(), run_loop(), save_tasks(), set_error_callback(), set_task_complete_callback(), start(), task_scheduler(), task_scheduler(), task_scheduler(), and ~task_scheduler().
|
private |
Condition variable for sleep/wake.
Definition at line 686 of file task_scheduler.h.
Referenced by run_loop(), and stop().
|
private |
Reference to PACS index database.
Definition at line 665 of file task_scheduler.h.
|
private |
Execution history (task_id -> records)
Definition at line 701 of file task_scheduler.h.
Referenced by clear_history(), and record_execution().
|
private |
IExecutor for task execution (recommended, Issue #487)
Definition at line 674 of file task_scheduler.h.
|
private |
|
mutableprivate |
Mutex for execution history.
Definition at line 704 of file task_scheduler.h.
Referenced by clear_history(), and record_execution().
|
mutableprivate |
Mutex for thread synchronization.
Definition at line 683 of file task_scheduler.h.
Referenced by run_loop(), set_error_callback(), and set_task_complete_callback().
|
mutableprivate |
Next execution ID counter.
Definition at line 722 of file task_scheduler.h.
Referenced by generate_execution_id().
|
mutableprivate |
Next task ID counter.
Definition at line 719 of file task_scheduler.h.
Referenced by generate_task_id().
|
private |
Flag indicating scheduler is running.
Definition at line 692 of file task_scheduler.h.
Referenced by get_stats(), is_running(), start(), and stop().
|
private |
Running task count.
Definition at line 707 of file task_scheduler.h.
Referenced by execute_cycle(), get_stats(), and running_count().
|
private |
Background scheduler thread.
Definition at line 680 of file task_scheduler.h.
|
private |
Start time for uptime calculation.
Definition at line 716 of file task_scheduler.h.
Referenced by get_stats(), and start().
|
private |
Scheduler statistics.
Definition at line 710 of file task_scheduler.h.
Referenced by execute_cycle(), get_stats(), and update_stats().
|
mutableprivate |
Mutex for statistics.
Definition at line 713 of file task_scheduler.h.
Referenced by execute_cycle(), get_stats(), and update_stats().
|
private |
Flag to signal shutdown.
Definition at line 689 of file task_scheduler.h.
Referenced by run_loop(), start(), and stop().
|
private |
All scheduled tasks (id -> task)
Definition at line 695 of file task_scheduler.h.
Referenced by execute_cycle(), get_stats(), list_tasks(), pending_count(), and serialize_tasks().
|
mutableprivate |
Mutex for tasks map.
Definition at line 698 of file task_scheduler.h.
Referenced by execute_cycle(), get_stats(), list_tasks(), pending_count(), and serialize_tasks().
|
private |
Thread pool for parallel task execution (legacy)
Definition at line 671 of file task_scheduler.h.