You are not logged in.

Unanswered posts



Important! This site has been replaced. All content here is read-only. Please visit our brand-new community at https://community.talend.com/. We look forward to hearing from you there!



#1 2011-03-23 06:37:53

alevy
Member
1923 posts

alevy said:

[resolved] How to have a job commit suicide if it takes too long

Does anyone have any suggestions as to the best way to build a job so that it commits suicide if the execution is taking too long?

My first thought is possibly having after the output component (or from a tReplicate before a component like tSort): --flow--> tFlowToIterate --iterate--> tJava --if--> tDie
where the condition is based on the system time vs the time the job commenced.

But what if you're using a t[DB]Row component to execute a SQL statement?  Would you have to use tParallelize with one branch being your actual job and the other being a loop triggering tDie after a certain period of elapsed time?

Last edited by alevy (2011-03-23 06:38:25)

Offline

#2 2011-03-23 16:07:16

emaxt
Member
328 posts

emaxt said:

Re: [resolved] How to have a job commit suicide if it takes too long

Well a quick solution is to use a tJava component at the beginning of the job registering a monitor to kill the process, ie. in tjava to kill the process after 5 seconds (5000ms):

----------------
java.util.TimerTask monitorTask = new java.util.TimerTask() {
        public void run() { System.err.println("Shutting down job");
                            System.exit(0);
        }
};
java.util.Timer monitorTimer = new java.util.Timer();
monitorTimer.schedule(monitorTask, 5000);
--------------

hope it helps.

Of course if you need many times this kind of stuff is better to delegate this kind of cross-cut concern to an external scheduler.
bye

Offline

#3 2011-03-24 01:37:02

alevy
Member
1923 posts

alevy said:

Re: [resolved] How to have a job commit suicide if it takes too long

Thanks for the suggestions.  What I really want, though, is to add this logic to a child job that is being repeatedly called so that individual iterations can be terminated but the parent will continue on to the next iteration.  That would certainly seem to disallow the use of an external scheduler for the purpose.  Your tJava suggestion also seems to prevent things like logging/tidying up?

Offline

#4 2011-03-24 15:45:39

emaxt
Member
328 posts

emaxt said:

Re: [resolved] How to have a job commit suicide if it takes too long

You can execute the child job as a separate process (check the option in trunjob) and then you can include the code provided above in the start of child job.

If you need some logging inside the child job, and you can't live with standard error output... you can do something more sophisticated, like defining a standard talend tlogcatcher and then you can inject an exception from the monitor thread.
in tjava:
-----------------------------------
final int timeoutInSeconds = 5;
final java.lang.Thread currentThread = Thread.currentThread();

java.util.TimerTask monitorTask = new java.util.TimerTask() {
        public void run() {
            currentThread.stop(new java.lang.Exception("Timeout!!!"));
        }
};
java.util.Timer monitorTimer = new java.util.Timer();
monitorTimer.schedule(monitorTask, timeoutInSeconds*1000);
-----------

bye

Offline

#5 2011-03-24 22:52:58

alevy
Member
1923 posts

alevy said:

Re: [resolved] How to have a job commit suicide if it takes too long

Thanks a lot.  I guess it helps if you know any Java at all wink

Offline

#6 2011-03-31 02:43:34

alevy
Member
1923 posts

alevy said:

Re: [resolved] How to have a job commit suicide if it takes too long

Don't know what it is about this topic but it won't let me set it as resolved sad

Offline

#7 2011-03-31 11:24:25

pcoffre
Member
785 posts

pcoffre said:

Re: [resolved] How to have a job commit suicide if it takes too long

Hi alevy, thanks for the notification, just set the topic as resolved.
The topic can't be set to resolved if it has quotation marks in the title, so edited it.

Thank you,
Pcoffre.


Follow Talend on Twitter, Linkedin and Facebook.
Download and try Talend solutions

Offline

Board footer

Talend Contributor Agreement - Talend Website Privacy Policy