[Coldbox 6.5.2] Coldbox Scheduled Tasks and Possible Visualizer?

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. :slight_smile:

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.

1 Like

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 );
    };

} );
1 Like

You should start work on the task visualizer. You can model it after the route visualizer :slight_smile:

That sounds like a fun project. I’m currently working on some enhancements for cbvalidation. Once I get those completed, I’ll take a stab at this one.

1 Like

That’s great @DaveL

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.

2 Likes

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;

Generated Output (ACF 2018)

Note the tasks key only lists the “Admin Heartbeat” task.

If you use the following code in your handler instead:

function index( event, rc, prc ) {
       
    prc.tasks = [];

    var rootTasks = wirebox.getInstance( "appScheduler@coldbox" ).getTasks();
    rootTasks.each( function( key, value ) {
        value[ "module" ] = "";
        prc.tasks.append( value );
    } );
    
    // 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#" ).getTasks();
            //writeDump( var=scheduler, top=4 );

            scheduler.each( function( key, value ) {
                value[ "module" ] = item;
                prc.tasks.append( value );
            } );
        };

    } );

    writeDump( var=prc.tasks, top=3 );

    abort;

You will see each task registered in the app:

@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?

Actually this is a bug. Resolved on bleeding edge

1 Like

Awesome! That was fast!

If you’re still in that code, I created another related issue where nextRun doesn’t get populated in the task stats:
https://ortussolutions.atlassian.net/browse/COLDBOX-1068