I’ve been playing around with the new Coldbox Scheduled tasks feature recently. So far, it’s awesome and incredibly powerful. I can’t wait to say goodbye to cfschedule forever.
One thing I’ve done in legacy apps was to create a cfschedule based visual interface for reporting all application-wide tasks so I could check their stats (date last ran, etc…).
I know Coldbox has a global scheduled task object, appScheduler@coldbox, but that object doesn’t contain references to any tasks created by submodules. Is there a way to get a list of all tasks currently registered on the current app? In fact, while I’m thinking about it, are there plans to eventually create some type of ForgeBox module for visualizing scheduled tasks similar to the route visualizer?
@lmajano says yes he wants to build that. You should be able to get the information about each task. I think each module has its own scheduler, so you’d need to iterate over all active modules and get their scheduler.
Sweet. This little code snippet dumps the root app scheduler and then loops through all loaded modules. If the module has a cbScheduler mapping, it dumps it:
// root app scheduled tasks
writeDump( "Root" );
writeDump( var=wirebox.getInstance( "appScheduler@coldbox" ), top=2 );
// get all loaded modules
var loadedModules = controller.getModuleService().getLoadedModules();
// loop through each loaded module, if the cbscheduler mapping exists, get it.
loadedModules.each( function( item, index ) {
if ( wirebox.getBinder().mappingExists( "cbScheduler@#item#" ) ) {
writeDump( item );
var scheduler = wirebox.getInstance( "cbScheduler@#item#" );
writeDump( var=scheduler, top=2 );
};
} );
Please note that ALL schedul;ers regardless of where they come from are managed and stored by the SchedulerService which can be injected via coldbox:schedulerService or get via controller.getSchedulerService(). This service is used to manage all schedulers in the application, new registraitons, etc.
Now, as far as visualizers go, the cbdebugger module is the one to tap into. The idea is for the debugger to be the one-stop show for ColdBox debugging and the developer tool.
I have already added an executor tab to it, that can show you all the executors, their internal tasks, etc. However, a Schedule Task Visualizer for the debugger would be incredible.
Interesting… I’m not sure if this is intentional behavior or not, but I wanted to see if I could get a list of all scheduled tasks by using SchedulerService. In my test, I was only able to see the task(s) from the sub module.
Here’s my setup:
/config/Scheduler.cfc
task( "Root Hearbeat" )
/modules_app/caffeinecms/config/Scheduler.cfc
task( "Admin Hearbeat" )
Create a handler to output the scheduled tasks
/modules_app/caffeinecms/handlers/scheduledTasks.cfc OR
/handlers/scheduledTasks.cfc
function index( event, rc, prc ) {
var schedulerService = controller.getSchedulerService();
writeDump( var=schedulerService.getSchedulers(), top=3 );
abort;
@lmajano shouldn’t SchedulerService retrieve all tasks regardless of whether they exist in a module or the root? Or perhaps I’m not calling the right method?