Stopping a graph midway

Support/help with CloverETL (4.9) and CloverDX (5.0 or newer) implementation problems

jasoncoeho
Posts: 2
Joined: Thu Jun 25, 2009 4:20 pm

Stopping a graph midway

Postby jasoncoeho » Thu Jun 25, 2009 4:25 pm

I have a graph where I read data from a file. If there is no data read - I would like to stop execution of the remainder of the graph. Any ideas on how to do this ?

avackova
Posts: 841
Joined: Fri Jul 20, 2007 9:28 am

Re: Stopping a graph midway

Postby avackova » Fri Jun 26, 2009 10:09 am

Hello,
you should check the file before running the graph and, if it is empty, don't run such graph at all.
But if you persist on aborting graph by itself, it can be done in Reformat component. See following example class you can use in Reformat component:

Code: Select all

import org.jetel.component.DataRecordTransform;
import org.jetel.data.DataRecord;
import org.jetel.exception.TransformException;


public class StopGraph extends DataRecordTransform {

   int recNo=0;
   
   public int transform(DataRecord[] arg0, DataRecord[] arg1)
         throws TransformException {
      defaultTransform(arg0, arg1);
      recNo++;
      return ALL;
   }

   public void finished() {
      if (recNo == 0) {
         System.err.println("There is no data. Killing the graph.");
         getGraph().getWatchDog().abort();
      }
   }
}

In transform method you just copy input record to output record and in finish method you kill the running graph. The Reader and Reformat should be in earlier phase than the rest of graph. Note that such solution make your graph slower for not empty files while you have to split the graph into the phases and add one more Reformat.
Agata Vackova
Javlin a.s.
[email protected]

mukunku
Posts: 6
Joined: Wed Nov 01, 2017 3:49 pm

Re: Stopping a graph midway

Postby mukunku » Thu Nov 09, 2017 4:07 pm

Thanks for the abort logic:

Code: Select all

getGraph().getWatchDog().abort();

There should definitely be an Abort component by default that does this

imriskal
Posts: 397
Joined: Wed Aug 15, 2012 8:18 am

Re: Stopping a graph midway

Postby imriskal » Fri Nov 10, 2017 8:23 am

We actually do have a component called Fail now. It requires at least one record flowing into it to work but this can be worked around by using a dummy record.
---
Lubos Imriska
CloverCARE Support
CloverDX

Visit us online at http://www.cloverdx.com

mukunku
Posts: 6
Joined: Wed Nov 01, 2017 3:49 pm

Re: Stopping a graph midway

Postby mukunku » Fri Nov 10, 2017 5:09 pm

Hi @imriskal,

Could a status code option be added to the fail component? Such as "End as Failed" or "End as Aborted".

One example scenario I have is that I have a failed graph event listener that emails when something goes wrong. But there are times when I just want to abort the graph without triggering an "error".

An option to just end the graph as "Success" would be helpful in this regard as well. Maybe an option to the existing Success component can be added that says "Cancel future phases and end graph after current phase finishes".

bartonv
Posts: 136
Joined: Wed May 03, 2017 12:10 pm

Re: Stopping a graph midway

Postby bartonv » Thu Nov 30, 2017 3:26 pm

Hi Mukunku,
the fail component is designed in a way that it can abort the parent jobflow or graph with a user-specified error message and at the same time return some results through the dictionary. Having said that, you could use the Fail component for both purposes. Let me present you with an example:

  1. Adding a Status Code
    • You would place Fail as a standalone component in the very last phase of your jobflow.
    • You could assign a user-specified error message, “End as Aborted” for instance.
    • This would help you distinguish between a jobflow that ended by this intentional user abort and a jobflow that finished with an actual error.
  2. Cancel future phases and end graph after current phase finishes
    • Let’s say you have at least 2 different phases in your jobflow.
    • If you placed the Fail component in between those 2 existing phases, you could intentionally prevent the higher phase from being executed.
Note: this could not be achieved by using the Success component as it does not function as a stopper and the graph/jobflow would simply continue to run.

Please also note that the aforementioned examples would answer just the basic questions. If they do not address your particular situation sufficiently, feel free to provide us with the graph in question so that we can get a better insight into the specific case. In similar situations, a minor redesign of a graph might do the trick.

Regards,
---
Vladimir Barton
CloverCARE Support
CloverDX

Visit us online at http://www.cloverdx.com


cron