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.[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.onStartup()
onShutdown()
onAnyTaskError(task,exception)
onAnyTaskSuccess(task,result)
beforeAnyTask(task)
afterAnyTask(task,result)
setCacheName( cacheName )
setServerFixation( boolean )
setTimezone( timezone )
setExecutor( executor )
template
cache when doing server fixation. You can override the cachename by a task by task basis or set the global default into the scheduler.onOneServer()
method of the individual scheduled task. However, you can also tell the scheduler to do this for ALL tasks it manages using the setServerFixation()
method.setTimeZone()
method and pass in a valid timezone string:scheduled
executor with a default of 20 threads for you with a name of [email protected]
If you want to add in your own executor as per your configurations, then just call the setExecutor()
method.variables
scopeasyncManager
cachebox
cacheName
controller
executor
log
started
serverFixation
tasks
timezone
util
wirebox
announce()
externalView()
getCache()
getColdBoxSetting()
getEnv()
getInstance()
getModuleConfig()
getModuleSettings()
getRenderer()
getSetting()
getSystemSetting()
getSystemProperty()
layout()
locateDirectoryPath()
locateFilePath()
runEvent()
runRoute()
settingExists()
setSetting()
getRegisteredTasks()
getTaskRecord( name )
{
name,
task,
future,
scheduledAt,
registeredAt,
error,
errorMessage,
stacktrace
}
getTaskStats()
hasTask( name )
hasStarted()
removeTask( name )
startup()
shutdown()
task( name )
task( name )
method.ColdBoxScheduledTask
object for you, configure it, wire it, register it and return it to you.call()
method on the task object. You can register a closure/lambda or a invokable CFC. If you register an object, then we will call on the object's run()
method by default, but you can change it using the method
argument and call any public/remote method.timeUnit
the available options are:every( period, timeunit )
spacedDelay( spacedDelay, timeunit )
everyMinute()
everyHour()
everyHourAt( minutes )
everyDay()
everyDayAt( time )
everyWeek()
everyWeekOn( day, time )
everyMonth()
everyMonthOn( day, time )
onFirstBusinessDayOfTheMonth( time )
onLastBusinessDayOfTheMonth( time )
everyYear()
everyYearOn( month, day, time )
onWeekends( time )
onWeekdays( time )
onMondays( time )
onTuesdays( time )
time
arguments are defaulted to midnight (00:00)withNoOverlaps()
method and ColdBox will register the tasks with a fixed delay. Meaning the intervals do not start counting until the last task has finished executing.spacedDelay( delay, timeUnit )
method in the Task object.delay()
method.delay
is numeric and the timeUnit
can be:delay
pushes the execution of the task into the future only for the first execution.after( target )
function( task, results )
before( target )
function( task )
onFailure( target )
function( task, exception )
onSuccess( target )
function( task, results )
setTimezone( timezone )
method:when()
closure that will be executed at runtime and boolean evaluated. If true
, then the task can run, else it is disabled.onOneServer()
method which tells ColdBox to ONLY run the task once on the first server that wins the race condition.template
cache provider in CacheBox. However, you can change which cache provider will be used for storing the locking and tracking entries.environment
setting. You can use that to register a task with constraints of environment using the onEnvironment( environment )
method. This means that the task will ONLY run on those environments. The environment
argument can be a single string, a list of environments or an array of environments.disable()
method:enable()
method:getStats()
method to get a a snapshot structure
of the stats in time. Here is what you get in the stats structure:created
inetHost
lastRun
lastResult
localIp
neverRun
nextRun
totalFailures
totalRuns
totalSuccess
err( var )
getCache()
getCacheName()
getEnvironments()
getServerFixation()
hasScheduler()
isDisabled()
isConstrained()
out( var )
setCacheName()
start()
config/Scheduler.cfc
that if detected will register that scheduler for you with a WireBox ID of [email protected]{moduleName}
. ColdBox will register the scheduler for you and also store it in the module's configuration struct with a key of scheduler
. ColdBox will also manage it's lifecycle and destroy it if the module is unloaded. All the rules for schedulers apply, happy scheduling!