[Coldbox 6.5.2] How to Get Current Module Settings When Creating Scheduled Task?

I’m experimenting with creating ColdBox scheduled tasks in modules, and I’d like to be able to use module settings (and overrides) so that I can have some flexibility with each tasks setup. For example, I may want to default the task to run every 12 hours, but I want the option to override it via config so that it will run every 24 hours.

I put together a rough way to perform what I want, but I’m wondering if there’s a smarter way to go about doing this? For example, I’d like to get the current module’s settings automatically without having to explicitly state the module name. I checked the variables scope but there doesn’t seem to be a method available here named getCurrentModuleName() or anything similar.

What I’ve done is set up my modules config/Scheduler.cfc like this:

component {
    /**
     * Configure the ColdBox Scheduler
     */
    function configure() {
        
        // explicitly get the module settings (note: there must be a better way!)
        var moduleSettings = getModuleSettings( "admin" );

        task( "Hearbeat" )
            .call( function() {
                writeDump( var="Heartbeat", output="Console" );
            } )
            .every( moduleSettings.scheduler.period, moduleSettings.scheduler.timeUnit );
1 Like

I think you bring about a good point. All Schedulers are built by wirebox, so we can definitely take advantage of injections and runtime additons.

As of now, this is new territory so ideas are totally welcomed. Maybe we can think about injecting several variables like we do with the ModuleConfig. I say, create a ticket for injecting module context variables to module schedulers. I would also suggest we do the same for the global scheduler and inject the global context variables like appName appMapping etc.

2 Likes

Thanks @lmajano :slight_smile:

Issue created here:
https://ortussolutions.atlassian.net/browse/COLDBOX-1067