Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Talend Cloud AWS EU Scheduled Outage: Starting Tues 26 May 21:00 CEST with expected completion Wed 27 May 01:00 CEST
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

[resolved] Parent and Child Jobs - Contexts

I am working on my first project. I have created 10 jobs that basically extract data from a SQL Server database and create 10 different CSV files. I am making use of context variables to externalize all connection info etc. so we can have different settings for each environment, DEV, TEST and Production.
.
In most cases we require one controlling job that will call each of the separate jobs, so only one job needs to be scheduled. So I am defining a controlling job that will use tRunjob to call the jobs. I am planning on passing the context's down to the child jobs. My questions are
.
In the child jobs, do we have to do anything to load the context's or since they are passed from the parent job nothing is required.?
.
Secondly if for some reason someone wanted to schedule and run one of the child jobs independently I am presuming this would have to load the contexts since it is not getting called from the parent job, what way would you handle this, or would you force everything to go through the parent job and some configuration setting to allow the user to indicate if they want only one job to run.

Regards,
Derek
Labels (4)
1 Solution

Accepted Solutions
alevy
Specialist
Specialist

In the parent job, don't forget to check the "Transmit whole context" option in tRunJob.
In the child job, your first component should just be an empty tJava. From that have an If trigger (!"Y".equals(context.is_it_called_from_parent)) to tFileInput --> tContextLoad. Then just OnSubjobOK from the tJava to the real part of your job.
You can also, if you want, use an If trigger ("Y".equals(context.is_it_called_from_parent)) from tJava and an OnComponentOK from tContextLoad (or OnSubjobOK from tFileInput) to the real part of your job.

View solution in original post

6 Replies
Anonymous
Not applicable

Hello,
For the first question you can find a great article here:
Talend Subjobs: Passing Full Context to tRunJob
http://jufeappdev.blogspot.fr/2013/02/talend-trunjob-passing-full-context.html
_AnonymousUser
Specialist III
Specialist III
Author

Thanks for the link, I had seen this before but I reread it again. From this article what I gathered is that I should define the same context variables in the child that exists in the parent.
.
So the logic I am trying to implement in the child job is as follows

(the context is_it_called_from_parent will be set to 'Y' in the Parent Job.)
at the beginning

a. check context.is_it_called_from_parent ='N' Then execute tContext_load
b. If context.is_it_called_from_parent='Y' Then skip tContext_load
c. continue with child job
.
but I having trouble figuring out how to implement this, can you can have a condition ie. If clause and then link back so the job continues?

Derek
alevy
Specialist
Specialist

In the parent job, don't forget to check the "Transmit whole context" option in tRunJob.
In the child job, your first component should just be an empty tJava. From that have an If trigger (!"Y".equals(context.is_it_called_from_parent)) to tFileInput --> tContextLoad. Then just OnSubjobOK from the tJava to the real part of your job.
You can also, if you want, use an If trigger ("Y".equals(context.is_it_called_from_parent)) from tJava and an OnComponentOK from tContextLoad (or OnSubjobOK from tFileInput) to the real part of your job.
Anonymous
Not applicable

Correct. Please take care, the first job contains all needed context variables which are used in the embedded job, only in this case the option "Transmit whole context" make sense.
_AnonymousUser
Specialist III
Specialist III
Author

Thanks for all the responses.
.
I have it working, where I load the context's in the parent and then call all the child jobs. If a child gets scheduled to run on it's own it will check a context and determine that it needs to execute tContext_load.
.
The one simple thing I had to figure out was the difference between onSubJobOk and OnComponentOk, making use of OnComponentOk to link subjobs allow them all to be executed as one SubJob so the job will not continue till all the jobs that make up reading context's is completed.
.
Here is a link I liked for working with context's that I based my solution of.
http://www.talendbyexample.com/talend-load-context-example.html
Anonymous
Not applicable

This tutorial has now been improved so that context can be loaded using a SubJob.
http://www.talendbyexample.com/talend-reusable-context-load-job.html