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