One Star

Job behavior when prejob fails

I'm trying to understand the exact behavior of tPrejob component and would be glad if someone could help me. Please refer to the attached image.
From my understanding, after reading section 4.4.5 (pages 83-84) from TalendOpenStudio_UG_40b_EN, and tPrejob Section (page 1075) from TalendOpenStudio_Components_RG_40b_EN, the tPrejob would execute before the other flows, so that if there was an error in the prejob, I would expect that any other flows would not be executed. In other words, if the prejob could not finish, I thought none of the other flows would even start.
Well, when I run my job, if the tFileInputDelimited runs ok, three messageboxes are displayed as expected: finishedPrejob, finished1 and finished2. If I make the tFileInputDelimited fail (for example, file does not exist), I don't get the finishedPrejob msgbox, but I still get the other two.
Of course, if I connect the tPrejob (see second image) to one of the other msgbox componets, everything fails as I expected, but then, as far as I understand it, everything will be part of the prejob, right?
Is there any other way to make the whole job die if the prejob dies, other than having the whole flow as a huge prejob?
8 REPLIES
Seven Stars

Re: Job behavior when prejob fails

You could have an OnSubjobError from the tPreJob to a tDie. But the point of tPreJob is to let the rest of the job run regardless of what happens in the tPrejob...
One Star

Re: Job behavior when prejob fails

You could have an OnSubjobError from the tPreJob to a tDie. But the point of tPreJob is to let the rest of the job run regardless of what happens in the tPrejob...

Hi alevy, thank you for your reply! I connected my failing component from the prejob to a tDie, but it still didn't work. The only difference was an extra error message in the console ("the end is near"). The other flow is still executed, even after the execution of the tDie, as you can see from the first attached image. I tried both links, OnSubjobError and OnComponentError, with the same results. And in tDie I tried the options "Error" and "Fatal".
I think I misanderstood the purpose of tPrejob. I was planning to run something like a "prejob" to test some conditions necessary for my main flow to run, and kill the execution if those conditions are not met. I guess the prejob is not what I need. Instead, I'm going to use a RunIf trigger to run the main flow only if the conditions apply.
But I still don't quite understand why to use a tPrejob. In page 84 of the TalendOpenStudio_ug_40b_en.pdf, the picture shows a prejob that loads context variables, opens a database connection and verifies if a file exists (see the second attached image). If there is any error during that prejob, the main flow will still be executed, which won't be good!
It would be nice to have some way to allow the whole job to die if the prejob dies, avoiding the execution of a main flow that depends on tasks the prejob should have accomplished.
Thanks for your help!
Doug
Seven Stars

Re: Job behavior when prejob fails

The other flow is still executed, even after the execution of the tDie... And in tDie I tried the options "Error" and "Fatal".

I think the Priority option in tDie doesn't actually do anything. However, there's an advanced option on the component ("Exit the JVM immediately") that will probably do what you wanted.
I still don't quite understand why to use a tPrejob.

That's certainly not a useful example in the UG. However, if the tMySqlConnection were part of the main job instead of the pre-job then the job design would allow the load from Excel to MySQL to happen using the default context values even if the load of new context values from the file failed.
That's still perhaps of limited use. I can't think of a better example off-hand; I've never used tPrejob myself but my jobs have all been pretty simple so far. Perhaps it's best used only for a "clean" job design or to allow for parallel execution of multiple subjobs that are all dependent on the same pre-job.
It would be nice to have some way to allow the whole job to die if the prejob dies

I would simply use an OnSubjobOK link from your pre-processing for this rather than a tPreJob.
Four Stars

Re: Job behavior when prejob fails

I'm having a similar issue. Basically, at the end of my tPreJob flow (there are multiple sub-jobs connected with OnSubJobOk) I have a tJavaFlex that throws a RuntimeException if something in my logic fails. If it passes, then great, the main job continues as it should. However, if it fails I want the whole job to end there, and perhaps ,if anything, just go straight to the tPostJob.
The issue I am having is that when the tPreJob flow fails, the main job continues when I don't want it to, even with the RuntimeException. How can I stop this from happening? I can't use OnSubJobOk because my flow is all connected through OnSubJobOk and I need the tPreJob and the Main job as they are.
Seven Stars

Re: Job behavior when prejob fails

Why can't you use OnSubjobOK? Put up a screenprint.

Re: Job behavior when prejob fails

when the tPreJob flow fails, the main job continues when I don't want it to

The pre-job component is intended to work this way.

If you want a hard-stop if something in the pre-job is screwy try this:
create a context variable: context.go_code
in your pre-job, set it to something if things go bad.
in your main job, check this variable and handle the error.
Four Stars

Re: Job behavior when prejob fails

Here is a screenshot.
I already tried connecting the pre-process with the main job with a OnSubJobOK, the problem with that is that the main job's starting point is a tFileList and I need it to iterate. If its connected with a onSubJobOk, it does not iterate successfully, instead it stops after the first successful import. The way I have it now, will in fact iterate until all files are complete. The only issue I am having is that the main job should not start if the pre-process fails, which I was hoping would work with a RuntimeException.
Seven Stars

Re: Job behavior when prejob fails

I've never had any problem with tFileList iterating correctly when started from an OnSubjobOK. Perhaps you could try putting an empty tJava between the tFileList at the start of the main job and the following tFileInputDelimited and see if that makes a difference.
Otherwise, Garrett's suggestion will work: define a context variable (e.g. Proceed = false) and then at the end of the pre-job, if successful, change it to true. Then start your main job with an empty tJava connected by RunIf (condition: context.Proceed) to the tFileList.