I am migrating my apps from old CFML Scheduler to the Coldbox Scheduler. However, I’ve run into an issue that I can’t seem to resolve or troubleshoot very easily because the task executions don’t show up in FusionReactor. My guess is because the Coldbox task executions aren’t typical requests.
My goal is to execute an event within a task via runEvent()
, however the event requires a specific value in the rc
scope.
When my task executes, I see in the logs that the task fails. I would have expected a validation exception, but instead I get a null pointer exception.
Here’s my Scheduler.cfc configuration:
task( "HourlyMaintenance" )
.call( function() {
rc.name = "HourlyMaintenance"; // <-- required value in RC scope (Does not work)
runEvent(
event = "v1:maintenance.run",
eventArguments = {
scheduler = true
}
);
// ... etc.
The above doesn’t work, because runEvent()
doesn’t have access to the caller’s rc
scope.
The v1:maintenance:run
action fails validation via the following check at the beginning of the function:
function run( event, rc, prc, scheduler=false ) {
validateOrFail(
target = rc,
constraints = {
"name": {
required: true, // <-- validation fails here
requiredMessage: "You must specify the name of the maintenance plan you want to run."
}
}
);
// ... etc.
What’s strange is that instead of the expected validation exception, the Scheduler throws a null pointer exception in coldbox\system\RestHandler.cfc when it attempts to execute the setHTTPHeader()
method (line 1805) for the x-current-route
header. I have a feeling this might be a bug in the Coldbox scheduler, because I think it should be able to fail gracefully, just like a normal request.
// Name Exists
else if ( !isNull( arguments.name ) ) {
getPageContext()
.getResponse()
.addHeader( javacast( "string", arguments.name ), javacast( "string", arguments.value ) );
variables.responseHeaders[ arguments.name ] = arguments.value;
Aside from the above oddity, I am curious if there’s a way to access and populate the rc
scope from within a Coldbox task()
? The only workaround I can think of would be to use eventArguments
, but I try to use those sparingly because they often require more conditional checks in my handlers.
I would love it if runEvent()
had rcAppend
and prcAppend
arguments, similar to the Coldbox Router. Maybe this would be something to add to the Coldbox wish list.
If anyone has any other thoughts, workarounds, or ideas, please do share!