Scheduled Tasks
The ColdBox Scheduled Tasks offers a fresh, programmatic and human approach to scheduling tasks on your server and multi-server application
Scheduled tasks have always been a point of soreness for many developers in ANY language. Especially choosing where to place them for execution: should it be cron? windows task scheduler? ColdFusion engine? Jenkins, Gitlab? and the list goes on and on.

ColdBox Scheduled Tasks
The ColdBox Scheduled Tasks offers a fresh, programmatic and human approach to scheduling tasks on your server and multi-server application. It allows you to define your tasks in a portable Scheduler we lovingly call the
Scheduler.cfc
which not only can be used to define your tasks, but also monitor all of their life-cycles and metrics of tasks. Since ColdBox is also hierarchical, it allows for every single ColdBox Module to also define a Scheduler
and register their own tasks as well. This is a revolutionary approach to scheduling tasks in an HMVC application.The ColdBox Scheduler is built on top of the core async package Scheduler.
Every ColdBox application has a global scheduler created for you by convention and registered with a WireBox ID of
[email protected]
. However, you can have complete control of the scheduler by creating the following file: config/Scheduler.cfc
. This is a simple CFC with a configure()
method where you will define your tasks and several life-cycle methods.config/Scheduler.cfc
component {
/**
* Configure the ColdBox Scheduler
*/
function configure() {
/**
* --------------------------------------------------------------------------
* Configuration Methods
* --------------------------------------------------------------------------
* From here you can set global configurations for the scheduler
* - setTimezone( ) : change the timezone for ALL tasks
* - setExecutor( executorObject ) : change the executor if needed
* - setCacheName( "template" ) : Change the cachename for ALL tasks
* - setServerFixation( true ) : Set all tasks to run on one server
*/
/**
* --------------------------------------------------------------------------
* Register Scheduled Tasks
* --------------------------------------------------------------------------
* You register tasks with the task() method and get back a ColdBoxScheduledTask object
* that you can use to register your tasks configurations.
*/
task( "Clear Unregistered Users" )
.call( () => getInstance( "UserService" ).clearRecentUsers() )
.everyDayAt( "09:00" );
task( "Hearbeat" )
.call( () => runEvent( "main.heartbeat" ) )
.every( 5, "minutes" )
.onFailure( ( task, exception ) => {
getInstance( "System" ).sendBadHeartbeat( exception );
} );
}