Scheduled Tasks - Definite Bug(s)

CB Version in play: coldbox-6.6.1+2-202202172223

Take this example scheduled task from the \config\Scheduler.cfc:

task( "process-MyRVRadio-logs" )
			.call( function(){
				, eventArguments:{"scheduled":true, "logFile": "ScheduledTasks-Station.log"});
			.every(1, "minutes")	// No delay needed if disabled
			.delay(1, "minutes")	// No delay needed if disabled

Note the .disable() command. This is the difference. I have observed that when dumping this:

That tasks that are defined as disabled in the config, vs. those that are later disabled/enabled, there’s a difference. With NO configured .disabled(), these tasks all have a “future” key that is an object

When configured as disabled and later enabled, the “future” key is an empty string. In addition, there is a mismatch between the isDisabled() function call and the TaskRecord’s “disabled” property. These should definitely be synced. (Fortunately, I was always using the function instead of the property value.)


I discovered this by creating a UI that, with some heavy Javascript is showing me all the tasks, and with Ajax, determining how many seconds until the next run. I then have a countdown (00:05), (00:004) until the next run. Then, once that countdown hits zero, I refresh the data, and show how long its been running instead. Every five seconds, I get the task status info again, so I can update the on-screen stats, and now go back to showing the countdown til the next run.

Once I started changing the enabled/disabled status (disabled for local dev, enabled for production), I started to see these weird behaviors and wanted to let y’all know about them. I’m kind of stuck, as I don’t have any more time to play with my UI (I have not-fun work today.)

For now, I’m going to create all my tasks with a delay(5, “minutes”) and use some function (maybe onStartup in the scheduler config) to immediately disable all the tasks so they have the initial enabled state and will maintain their “future” object value that’s missing when initially disabled.

Still good stuff, just needs a bit more love!

This is the code I used to NOT configure .disable() on any of my tasks, but to ensure later .enable() on them would setup the Future object correctly:

function onStartup(){
	// Disable all tasks, because (bug) .disable() configured tasks never get a future object
	if( getSetting("Environment") != "Production" ){
		local.stSchedulers = controller.getSchedulerService().getSchedulers();
		loop collection=local.stSchedulers index="local.sSchedKey" item="local.oSched"{
			local.stTasks = local.oSched.getTasks();
			loop collection=local.stTasks index="local.sTaskName" item="local.stTask"{