Dynamic Context for tRunJob.

One Star

Dynamic Context for tRunJob.

Hello everyone,
I have a question about the tRunJob component.
I have a job with a Context Group that defines 4 different contexts: Dev, Prod, Sys and UAT (see attached images).
When I export the job as an autonomous job, I have to specify the context I want the job to called with.
What I would like to do is to be able to call my batch file with an argument to specify the context, something like this (from the command line):
UpdateSalesforceWithLastDateTime.bat Prod
and the batch file would be:
%~d0 cd %~dp0 java -Xms256M -Xmx1024M -cp classpath.jar; update_last_date_time.updatesalesforcewithlastdatetime_0_1.UpdateSalesforceWithLastDateTime --context=%1 %*
This way I would be able to reuse the same exported job for all my environments. But this is not possible, because the context to be used when calling the sub-job is hard-coded when the job is exported, so even if I pass the context as an argument, it is not used when the sub-job is run.
So in order for me to be able to run my job in the different environments I have to export it 4 times, one for each of the environments.
On my attempt to achieve this, I inspected the option "Use dynamic job" within the tRunJob component (see configuration on attachment).
My expectation was to be able to specify the "Context Job" and the "Context" attributes of the tRunJob as context variables; this way I would be able to control the context that is passed on to the sub-job.
However, this is what happened:
- The "Context Job" attribute can be passed from the context; so in my example, the "context.subjob" variable was replaced with "UpdateSalesforce" and the subjob is called as expected
- The "Context" attribute needs to have a value of an existing context group, its value cannot be passed from a context variable; so in my example, the "context.contextValue" variable was not replaced with "Prod" as I was expecting, but it used the value "context.contextValue", which does not exist in the Context Group and therefore the default context is used to call the sub-job (in this example the default context is "Dev")
Does anyone know if there is a way of achieving what I am looking for? Is this anything that is being added in future releases of Talend?
Thanks in advance,
Julipool

Re: Dynamic Context for tRunJob.

Hi,
Instead of executing the batch file with the default context, execute the contents of the batch file with the desired context group at runtime. For e.g. for Prod context group execute the below command:
java -Xms256M -Xmx1024M -cp classpath.jar; update_last_date_time.updatesalesforcewithlastdatetime_0_1.UpdateSalesforceWithLastDateTime --context=Prod
One Star

Re: Dynamic Context for tRunJob.

Hello dnahata_infocepts,
Many thanks for your response.
I have already tried that and it uses the "Prod" context for the parent job, but then it uses the default context (in my case "Dev") when calling the sub-job.
Kind regards,
Julipool

Re: Dynamic Context for tRunJob.

Hello dnahata_infocepts,
Many thanks for your response.
I have already tried that and it uses the "Prod" context for the parent job, but then it uses the default context (in my case "Dev") when calling the sub-job.
Kind regards,
Julipool

You need to Pass the context variables from Parent Job to subjob.
You can do this either by Transmit whole context or Passing it using Context Params.
One Star

Re: Dynamic Context for tRunJob.

Hello again,
Many thanks dnahata_infocepts for your comments.
I finally realised what the problem was. I had the option "Transmit whole context" activated, but the problem was that the parent job did not have the full context to be passed to the child job, so the child was using the default context.
I wrote a new entry on my blog about this in order to make it clearer, you are all welcome to read it:
http://jufeappdev.blogspot.co.uk/2013/02/talend-trunjob-passing-full-context.html
The thread will be now marked as solved.
Best regards,
Julipool