Skip to main content
justincook704
Participating Frequently
May 9, 2018
Question

How can I move to the next link in the chain of Chained Scheduled Tasks if one of the tasks fails?

  • May 9, 2018
  • 3 replies
  • 1249 views

So I have about 20 tasks that are chained.  Let's say that task number 5 fails, I'd like to move on to task number 6.  So I researched and found the event listener functions such as onTaskStart, onTaskEnd, onMisfire, onError.  But I am wondering if there is some variable that ColdFusion has built in so that I'd know what the next task in the chain is for me to call the execute functionality to kick it off.  Or is there a better way to handle this sort of scenario?

Thanks,

Justin

This topic has been closed for replies.

3 replies

Adobe Employee
May 15, 2018

Hi Justin,

I believe you have an eventhandler attached to your schedule tasks. Context argument is passed to the OnError method. It is a struct that has following keys:

  • Task
  • Mode
  • Group
  • ExceptionMessage

Thus, you can determine which task failed and write the logic of executing the next task in the onError method..

-Suchika

Charlie Arehart
Community Expert
Community Expert
May 26, 2018

Suchika, are you saying that that something in that argument would help Justin to know *which task in the chain would have been next**? That's what's sought here.

It seems you're saying that by looking at that context, one can see the name of the current task, and I guess you mean then that one can lookup in the task what it's next in the chain would be. But Justin already had that, and sensed that was the only solution, and he was asking how to know that chained next task automatically. I offered some ideas, but he's not yet confirmed if those worked.

So I'm just asking if you can confirm whether your proposed answer DOES give that info, or if not, could you clarify how you think he would be able to automatically get that next task name?

(Even better would be some means to tell the event handler to proceed to that next task. Sure, he could use cfschedule once he knows the name, but I'd agree if he felt that since this is already an eventhander in the scheduled task mechanism itself, there should reasonably be some easier way to tell the mechanism to just "continue to the next in the chain".)

/Charlie (troubleshooter, carehart. org)
Charlie Arehart
Community Expert
Community Expert
May 26, 2018

Also, Suchika, if you look into the underlying way you guys may have implemented job chaining in Quartz (for readers: that's the open-source project which underlies the new scheduled task mechanism implemented in CF10 and above), I see at least one resource (from 2011) showing a couple of alternatives for how one could implement chaining in Quartz:

Chaining job execution in Quartz – Team Blog

Of course, we can't easily know how you did the chaining. But if you did use the jobdatamaps approach, I see that it offers a variable called NEXT_EXECUTION_JOB_NAME_KEY:

quartz JobDataMap Get a direct handle to the underlying Map.

If you could grab that and/or expose that to us in the eventhandler, that could help someone in Justin's situation. Just trying to advance the conversation for Justin. He presents an interesting scenario, and one which it would seem CF may be able to offer a simple solution.

/Charlie (troubleshooter, carehart. org)
Charlie Arehart
Community Expert
Community Expert
May 10, 2018

I'll add some thoughts if they may help. I don't know the answer, either (and I've seen the various other replies from today). Like Wolfshade, I have not done much with chained sched tasks (new in 10), let alone facing the challenge of how to handle if one in the chain files, how to somehow proceed to the next.

Have you tried dumping various variables (and scopes) in the eventhandlers, like oncomplete and onmisfire? There may be something is there.

As for just getting the name of "the next task" chained after some given one, I would think that either the Admin API or the cfschedule tag itself could help. I know that the tag has an action="list". I've not used it in years. Perhaps you can add the name of a task to get info on that task. But the Admin API should certainly be able to get that info.

Still, I'm with you in thinking it could be possible that something in the event handling of the task itself could help you know what was next in the chain for that very task. If you find it out, do report it for others.

/Charlie (troubleshooter, carehart. org)
justincook704
Participating Frequently
May 14, 2018

Not sure if this is the best solution, but mine is as follows:  I have a cfm page that I use to call a CFC that runs the actual work of the task.  I have a cftry/catch around the method call on the cfm page. If the task fails, the catch catches it and posts to my database table that this particular task failed, then it continues on running the tasks in the chain.  That was the best solution I could come up with.

Charlie Arehart
Community Expert
Community Expert
May 26, 2018

Justin, do you have any response to the suggestions I made and questions I'd asked. Can you confirm that they did not help, if that's the case? Asking also for the sake of future readers of the thread

/Charlie (troubleshooter, carehart. org)
WolfShade
Legend
May 9, 2018

I've never used "chained" scheduled tasks, so I can't speak from experience.  But I wonder if placing all the processing code within CFTRY/CFCATCH would allow the chain to continue unbroken?  Place a cfmail inside the cfcatch to notify you of the error and cfdump the #cfcatch# object for details.

Just my two cents.

HTH,

^ _ ^

justincook704
Participating Frequently
May 9, 2018

I had already considered a try/catch outside of using the cfschedule, however, I would have to add a field into my database that shows what the next scheduled task is to know and then query to pull that and then manually launch that task.  I was wanting to use the info in the cfscheduler to accomplish this.

WolfShade
Legend
May 9, 2018

Again, I have zero experience with chained tasks, however I am under the impression that unless you have something in the cfcatch that stops processing, it should automatically move on to the next scheduled task.  Unless the next task is specified in the cfschedule, in which case I can see where a try/catch would fail.  I assumed that the CFAdmin would control the order of the tasks.

V/r,

^ _ ^