I am continuing my exploration into the powerful Coldbox Scheduled Tasks feature. However, I’ve hit a snag when trying to run a scheduled task that calls a model object that has an injection DSL with provider:
in it. This problem seems to only exist in Adobe engines.
I created the following issue here:
https://ortussolutions.atlassian.net/browse/COLDBOX-1070
In case anyone wants to replicate the issue, or point out a mistake I made, here are the steps to reproduce:
- Create a new app and install a dependency like QB which needs to be loaded via the
provider:
injection DSL
coldbox create app
install qb
server set app.cfengine=adobe@2018 // Must use ACF
- Create a simple task module
/models/SimpleTask.cfc
component
hint="I am a simple scheduled task"
{
property name="qb" inject="provider:QueryBuilder@qb";
function run() {
// print that the task is running
writeDump( var="Simple scheduled task is running", output="console" );
var result = qb.select().from( "user" ).toSql();
// print that the task finished
writeDump( var=result, output="console" );
writeDump( var="Simple scheduled task finished running", output="console" );
}
}
- Create a scheduled task:
/config/Scheduler.cfc
component {
function configure() {
task( "SimpleTask" )
.call( function() {
writeDump( var="Running Simple Task", output="console" );
wirebox.getInstance( "simpleTask" ).run();
writeDump( var="Simple Task Complete", output="console" );
} )
.onFailure( function( task, exception ) {
writeDump( var="Simple Task Failed!", output="console" );
writeDump( var=exception, output="console" );
} )
.every( 15, "seconds" )
;
}
}
- Start your server and watch the console using
server log --follow
You will see the immediate execution of the task will succeed. However, subsequent executions (every 15 seconds) will throw an exception:
Detail: Scope information: {SCOPE={application},ENABLED={true},KEY={wireBox}}
ErrorCode: [empty string]
ExtendedInfo: [empty string]
Message: Injector not found in scope registration information
StackTrace: coldfusion.runtime.CustomException: Injector not found in scope registration information
The error message is slightly different if the scheduled task executes from a submodule, but I believe the issue is the same.