|
game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
|
Service for scheduling and running background tasks. More...
#include <task_scheduler.h>
Classes | |
| struct | Impl |
Public Types | |
| using | OnTaskComplete = std::function<void(const std::string& taskId, const TaskResult&)> |
| using | OnTaskError = std::function<void(const std::string& taskId, const std::string& error)> |
| using | OnTaskStateChange = std::function<void(const std::string& taskId, TaskState newState)> |
| using | TaskFunction = std::function<TaskResult()> |
Public Member Functions | |
| TaskScheduler () | |
| TaskScheduler (const TaskScheduler &)=delete | |
| ~TaskScheduler () | |
| std::string | addCacheCleanupTask (TaskFunction cleanupFunction, std::chrono::hours interval=std::chrono::hours(24)) |
| Add a cache cleanup task. | |
| std::string | addCloudSyncTask (TaskFunction syncFunction, std::chrono::minutes interval=std::chrono::minutes(30)) |
| Add a cloud sync task. | |
| std::string | addLogCleanupTask (TaskFunction cleanupFunction, std::chrono::hours interval=std::chrono::hours(168)) |
| Add a log cleanup task. | |
| std::string | addUpdateCheckTask (TaskFunction checkFunction, std::chrono::hours interval=std::chrono::hours(1)) |
| Add an update check task. | |
| int | cancelAllPendingTasks () |
| Cancel all pending tasks. | |
| bool | cancelTask (const std::string &taskId) |
| Cancel a task. | |
| int | cancelTasksByName (const std::string &name) |
| Cancel all tasks with a given name. | |
| std::vector< ScheduledTask > | getAllTasks () const |
| Get all scheduled tasks. | |
| int | getPendingTaskCount () const |
| Get number of pending tasks. | |
| std::vector< ScheduledTask > | getPendingTasks () const |
| Get pending tasks (sorted by next run time). | |
| int | getRunningTaskCount () const |
| Get number of running tasks. | |
| std::optional< ScheduledTask > | getTask (const std::string &taskId) const |
| Get a task by ID. | |
| std::optional< ScheduledTask > | getTaskByName (const std::string &name) const |
| Get a task by name. | |
| int | getTaskCount () const |
| Get number of scheduled tasks. | |
| std::vector< ScheduledTask > | getTasksByState (TaskState state) const |
| Get tasks by state. | |
| int | getTotalExecutedCount () const |
| Get total tasks executed since start. | |
| int | getTotalFailedCount () const |
| Get total failed tasks since start. | |
| bool | isPaused () const |
| Check if paused. | |
| bool | isRunning () const |
| Check if the scheduler is running. | |
| bool | loadTasks (const std::string &path) |
| Load scheduled tasks from disk. | |
| TaskScheduler & | operator= (const TaskScheduler &)=delete |
| void | pause () |
| Pause task execution. | |
| bool | pauseTask (const std::string &taskId) |
| Pause a recurring task. | |
| int | pruneFinishedTasks () |
| Remove completed/cancelled/failed tasks from the list. | |
| bool | rescheduleTask (const std::string &taskId, std::chrono::system_clock::time_point newTime) |
| Reschedule a task. | |
| void | resume () |
| Resume task execution. | |
| bool | resumeTask (const std::string &taskId) |
| Resume a paused task. | |
| std::string | runNow (const std::string &name, TaskFunction task, TaskPriority priority=TaskPriority::Critical) |
| Schedule a task to run immediately. | |
| bool | saveTasks (const std::string &path) const |
| Save scheduled tasks to disk. | |
| std::string | schedule (const TaskDefinition &def) |
| Schedule a task using a definition. | |
| std::string | scheduleAt (const std::string &name, std::chrono::system_clock::time_point when, TaskFunction task, TaskPriority priority=TaskPriority::Normal) |
| Schedule a task for a specific time. | |
| std::string | scheduleOnce (const std::string &name, std::chrono::seconds delay, TaskFunction task, TaskPriority priority=TaskPriority::Normal) |
| Schedule a one-shot task with a delay. | |
| std::string | scheduleRecurring (const std::string &name, std::chrono::seconds interval, TaskFunction task, TaskPriority priority=TaskPriority::Normal, bool runImmediately=false) |
| Schedule a recurring task. | |
| void | setOnTaskComplete (OnTaskComplete callback) |
| void | setOnTaskError (OnTaskError callback) |
| void | setOnTaskStateChange (OnTaskStateChange callback) |
| bool | setTaskInterval (const std::string &taskId, std::chrono::seconds newInterval) |
| Change the interval of a recurring task. | |
| void | start () |
| Start the scheduler. | |
| void | stop (bool waitForRunning=true) |
| Stop the scheduler. | |
| bool | triggerNow (const std::string &taskId) |
| Trigger immediate execution of a task. | |
Service for scheduling and running background tasks.
Provides a flexible system for scheduling tasks to run at specific times or at regular intervals.
Definition at line 171 of file task_scheduler.h.
| using TaskScheduler::OnTaskComplete = std::function<void(const std::string& taskId, const TaskResult&)> |
Definition at line 175 of file task_scheduler.h.
| using TaskScheduler::OnTaskError = std::function<void(const std::string& taskId, const std::string& error)> |
Definition at line 176 of file task_scheduler.h.
| using TaskScheduler::OnTaskStateChange = std::function<void(const std::string& taskId, TaskState newState)> |
Definition at line 177 of file task_scheduler.h.
| using TaskScheduler::TaskFunction = std::function<TaskResult()> |
Definition at line 174 of file task_scheduler.h.
| TaskScheduler::TaskScheduler | ( | ) |
Definition at line 168 of file task_scheduler.cpp.
Referenced by TaskScheduler(), and operator=().
| TaskScheduler::~TaskScheduler | ( | ) |
Definition at line 170 of file task_scheduler.cpp.
References stop().
|
delete |
References TaskScheduler().
| std::string TaskScheduler::addCacheCleanupTask | ( | TaskFunction | cleanupFunction, |
| std::chrono::hours | interval = std::chrono::hours(24) ) |
Add a cache cleanup task.
| cleanupFunction | Function that cleans caches |
| interval | How often to clean |
Definition at line 672 of file task_scheduler.cpp.
References TaskDefinition::description, TaskDefinition::interval, Low, TaskDefinition::name, TaskDefinition::priority, TaskDefinition::recurring, schedule(), and TaskDefinition::task.
| std::string TaskScheduler::addCloudSyncTask | ( | TaskFunction | syncFunction, |
| std::chrono::minutes | interval = std::chrono::minutes(30) ) |
Add a cloud sync task.
| syncFunction | Function that syncs cloud saves |
| interval | How often to sync |
Definition at line 659 of file task_scheduler.cpp.
References TaskDefinition::description, TaskDefinition::interval, TaskDefinition::name, Normal, TaskDefinition::priority, TaskDefinition::recurring, schedule(), and TaskDefinition::task.
| std::string TaskScheduler::addLogCleanupTask | ( | TaskFunction | cleanupFunction, |
| std::chrono::hours | interval = std::chrono::hours(168) ) |
Add a log cleanup task.
| cleanupFunction | Function that cleans logs |
| interval | How often to clean |
Definition at line 685 of file task_scheduler.cpp.
References TaskDefinition::description, TaskDefinition::interval, Low, TaskDefinition::name, TaskDefinition::priority, TaskDefinition::recurring, schedule(), and TaskDefinition::task.
| std::string TaskScheduler::addUpdateCheckTask | ( | TaskFunction | checkFunction, |
| std::chrono::hours | interval = std::chrono::hours(1) ) |
Add an update check task.
| checkFunction | Function that checks for updates |
| interval | How often to check |
Definition at line 645 of file task_scheduler.cpp.
References TaskDefinition::description, TaskDefinition::interval, TaskDefinition::name, Normal, TaskDefinition::priority, TaskDefinition::recurring, TaskDefinition::runOnStartup, schedule(), and TaskDefinition::task.
| int TaskScheduler::cancelAllPendingTasks | ( | ) |
Cancel all pending tasks.
Definition at line 482 of file task_scheduler.cpp.
| bool TaskScheduler::cancelTask | ( | const std::string & | taskId | ) |
Cancel a task.
| taskId | Task ID |
Definition at line 422 of file task_scheduler.cpp.
| int TaskScheduler::cancelTasksByName | ( | const std::string & | name | ) |
Cancel all tasks with a given name.
| name | Task name |
Definition at line 451 of file task_scheduler.cpp.
| std::vector< ScheduledTask > TaskScheduler::getAllTasks | ( | ) | const |
| int TaskScheduler::getPendingTaskCount | ( | ) | const |
Get number of pending tasks.
Definition at line 708 of file task_scheduler.cpp.
References getTasksByState(), and Pending.
| std::vector< ScheduledTask > TaskScheduler::getPendingTasks | ( | ) | const |
Get pending tasks (sorted by next run time).
Definition at line 407 of file task_scheduler.cpp.
References getTasksByState(), and Pending.
| int TaskScheduler::getRunningTaskCount | ( | ) | const |
Get number of running tasks.
Definition at line 713 of file task_scheduler.cpp.
References getTasksByState(), and Running.
| std::optional< ScheduledTask > TaskScheduler::getTask | ( | const std::string & | taskId | ) | const |
Get a task by ID.
| taskId | Task ID |
Definition at line 354 of file task_scheduler.cpp.
| std::optional< ScheduledTask > TaskScheduler::getTaskByName | ( | const std::string & | name | ) | const |
Get a task by name.
| name | Task name |
Definition at line 366 of file task_scheduler.cpp.
| int TaskScheduler::getTaskCount | ( | ) | const |
Get number of scheduled tasks.
Definition at line 702 of file task_scheduler.cpp.
| std::vector< ScheduledTask > TaskScheduler::getTasksByState | ( | TaskState | state | ) | const |
Get tasks by state.
| state | Task state to filter |
Definition at line 392 of file task_scheduler.cpp.
Referenced by getPendingTaskCount(), getPendingTasks(), and getRunningTaskCount().
| int TaskScheduler::getTotalExecutedCount | ( | ) | const |
Get total tasks executed since start.
Definition at line 718 of file task_scheduler.cpp.
| int TaskScheduler::getTotalFailedCount | ( | ) | const |
Get total failed tasks since start.
Definition at line 723 of file task_scheduler.cpp.
| bool TaskScheduler::isPaused | ( | ) | const |
Check if paused.
Definition at line 246 of file task_scheduler.cpp.
| bool TaskScheduler::isRunning | ( | ) | const |
Check if the scheduler is running.
Definition at line 222 of file task_scheduler.cpp.
| bool TaskScheduler::loadTasks | ( | const std::string & | path | ) |
Load scheduled tasks from disk.
| path | File path |
Definition at line 777 of file task_scheduler.cpp.
|
delete |
References TaskScheduler(), Critical, and Normal.
| void TaskScheduler::pause | ( | ) |
Pause task execution.
Definition at line 227 of file task_scheduler.cpp.
| bool TaskScheduler::pauseTask | ( | const std::string & | taskId | ) |
Pause a recurring task.
| taskId | Task ID |
Definition at line 512 of file task_scheduler.cpp.
| int TaskScheduler::pruneFinishedTasks | ( | ) |
Remove completed/cancelled/failed tasks from the list.
Definition at line 619 of file task_scheduler.cpp.
| bool TaskScheduler::rescheduleTask | ( | const std::string & | taskId, |
| std::chrono::system_clock::time_point | newTime ) |
Reschedule a task.
| taskId | Task ID |
| newTime | New scheduled time |
Definition at line 567 of file task_scheduler.cpp.
| void TaskScheduler::resume | ( | ) |
Resume task execution.
Definition at line 235 of file task_scheduler.cpp.
| bool TaskScheduler::resumeTask | ( | const std::string & | taskId | ) |
Resume a paused task.
| taskId | Task ID |
Definition at line 537 of file task_scheduler.cpp.
| std::string TaskScheduler::runNow | ( | const std::string & | name, |
| TaskFunction | task, | ||
| TaskPriority | priority = TaskPriority::Critical ) |
Schedule a task to run immediately.
| name | Task name |
| task | Task function |
| priority | Task priority |
Definition at line 345 of file task_scheduler.cpp.
References scheduleOnce().
| bool TaskScheduler::saveTasks | ( | const std::string & | path | ) | const |
Save scheduled tasks to disk.
| path | File path |
Definition at line 754 of file task_scheduler.cpp.
| std::string TaskScheduler::schedule | ( | const TaskDefinition & | def | ) |
Schedule a task using a definition.
| def | Task definition |
Definition at line 255 of file task_scheduler.cpp.
References ScheduledTask::createdAt, TaskDefinition::delay, ScheduledTask::description, TaskDefinition::description, InternalTask::function, generateUUID(), ScheduledTask::id, InternalTask::info, ScheduledTask::interval, TaskDefinition::interval, ScheduledTask::isRecurring, ScheduledTask::maxRetries, TaskDefinition::maxRetries, ScheduledTask::maxRuns, TaskDefinition::maxRuns, ScheduledTask::name, TaskDefinition::name, ScheduledTask::nextRunAt, Pending, ScheduledTask::priority, TaskDefinition::priority, TaskDefinition::recurring, TaskDefinition::runAt, ScheduledTask::runMissedOnStartup, TaskDefinition::runMissedOnStartup, ScheduledTask::runOnStartup, TaskDefinition::runOnStartup, ScheduledTask::scheduledFor, ScheduledTask::state, and TaskDefinition::task.
Referenced by addCacheCleanupTask(), addCloudSyncTask(), addLogCleanupTask(), addUpdateCheckTask(), scheduleAt(), scheduleOnce(), and scheduleRecurring().
| std::string TaskScheduler::scheduleAt | ( | const std::string & | name, |
| std::chrono::system_clock::time_point | when, | ||
| TaskFunction | task, | ||
| TaskPriority | priority = TaskPriority::Normal ) |
Schedule a task for a specific time.
| name | Task name |
| when | Time to run |
| task | Task function |
| priority | Task priority |
Definition at line 319 of file task_scheduler.cpp.
References TaskDefinition::name, TaskDefinition::priority, TaskDefinition::runAt, schedule(), and TaskDefinition::task.
| std::string TaskScheduler::scheduleOnce | ( | const std::string & | name, |
| std::chrono::seconds | delay, | ||
| TaskFunction | task, | ||
| TaskPriority | priority = TaskPriority::Normal ) |
Schedule a one-shot task with a delay.
| name | Task name |
| delay | Delay before running |
| task | Task function |
| priority | Task priority |
Definition at line 308 of file task_scheduler.cpp.
References TaskDefinition::delay, TaskDefinition::name, TaskDefinition::priority, schedule(), and TaskDefinition::task.
Referenced by runNow().
| std::string TaskScheduler::scheduleRecurring | ( | const std::string & | name, |
| std::chrono::seconds | interval, | ||
| TaskFunction | task, | ||
| TaskPriority | priority = TaskPriority::Normal, | ||
| bool | runImmediately = false ) |
Schedule a recurring task.
| name | Task name |
| interval | Time between runs |
| task | Task function |
| priority | Task priority |
| runImmediately | Run once immediately |
Definition at line 331 of file task_scheduler.cpp.
References TaskDefinition::interval, TaskDefinition::name, TaskDefinition::priority, TaskDefinition::recurring, TaskDefinition::runOnStartup, schedule(), and TaskDefinition::task.
| void TaskScheduler::setOnTaskComplete | ( | OnTaskComplete | callback | ) |
Definition at line 732 of file task_scheduler.cpp.
| void TaskScheduler::setOnTaskError | ( | OnTaskError | callback | ) |
Definition at line 738 of file task_scheduler.cpp.
| void TaskScheduler::setOnTaskStateChange | ( | OnTaskStateChange | callback | ) |
Definition at line 744 of file task_scheduler.cpp.
| bool TaskScheduler::setTaskInterval | ( | const std::string & | taskId, |
| std::chrono::seconds | newInterval ) |
Change the interval of a recurring task.
| taskId | Task ID |
| newInterval | New interval |
Definition at line 590 of file task_scheduler.cpp.
| void TaskScheduler::start | ( | ) |
Start the scheduler.
Begins processing scheduled tasks. Must be called before tasks will run.
Definition at line 179 of file task_scheduler.cpp.
References TaskScheduler::Impl::workerLoop().
| void TaskScheduler::stop | ( | bool | waitForRunning = true | ) |
Stop the scheduler.
| waitForRunning | Wait for currently running tasks to complete |
Definition at line 197 of file task_scheduler.cpp.
Referenced by ~TaskScheduler().
| bool TaskScheduler::triggerNow | ( | const std::string & | taskId | ) |
Trigger immediate execution of a task.
| taskId | Task ID |
Definition at line 603 of file task_scheduler.cpp.
References Pending.