• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

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

Views

689

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Okay.. here's a thought.. not tested..

<cftry>

     <cfset childTask = true />

    <cfschedule parentTask />

    <cfcatch>

          <cfmail><cfdump /></cfmail>

          <cfset childTask = false />

          <cfschedule childTask />

    </cfcatch>

</cftry>

<cfif childTask />

<cftry>

     <cfset childTask2 = true />

    <cfschedule childTask />

    <cfcatch>

          <cfmail><cfdump /></cfmail>

          <cfset childTask2 = false />

          <cfschedule childTask2 />

    </cfcatch>

</cftry>

</cfif>

Think this might work?

HTH,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

I wasn't programmatically kicking off the tasks, I'm using the administrator. However, here's what I did, I have a cftry/cfcatch. And if it fails, I use the cfschedule tag to kick off the next in the chain of events.  I had to add a field to my database table that lists the next event in the series so that the system knows which one to kick off next. I was hoping to use the information from the admin under On Complete to pull that out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

You _can_ use the admin API, I think, to get that information, but I am very leery of doing that.

As long as you know the names of the tasks, you shouldn't have to use a database to keep track.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Actually, now that I think of it, you should set the parentTask and all childTasks to true before the first CFTRY, then set them to false within the catch.  That way, if a child task was run within the cfcatch, it will skip the cftry child task and move on to the next.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

So I tried with the cfcatch and I use a cfschedule tag to run the task and now I get an error that says. The task is there in the scheduler, but it says it can't find it.  I also tried to use task name:group name and it didn't work either.

Tag as I am using: <cfschedule action="run" task="removeAssessmentFromInactiveSups"/>

Error:

The following task could not be found: removeAssessmentFromInactiveSups.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

That's a real head-scratcher, Justin.  I'm not sure how to proceed with that.  Maybe haxtbh​ or ALsp​ might have better understanding of it.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

I'm scratching my head as you spoke. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

As for this failing attempt to run the task, had you tried specifying the group attribute? You refer to using the name:group, but maybe you used that in the task attribute, like one would do in the oncomplete attribute when setting up a task to be chained).


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2018 May 26, 2018

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2018 May 26, 2018

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2018 May 26, 2018

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 26, 2018 May 26, 2018

Copy link to clipboard

Copied

LATEST

I haven't looked into this after I got it working, but I will spend sometime this coming week looking into your and Suchika's suggestions.  I will reply back with more information so that anyone else having this issue can hopefully have a clear cut answer.  I surely appreciate your time helping me with this and want to make sure that we can get a solution that is satisfying.

Thanks,

Justin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation