Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
0683p000009MDnb.png 0683p000009MDng.png 0683p000009MDhp.png
Labels (4)
8 Replies
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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
zjing
Contributor III
Contributor III

hello, 

I have a same issue. And I need the solution.

But I found, If this value for the context is in constant. Like "dev", "Production" And this works.

0683p000009M8D5.png

Mais if we use a variable for context, it dose not work.

 

Anonymous
Not applicable
Author

Hello Everybody,

Have you got a solution to resolved, the next message ?

I have a same problem.
the field contexte don't accept a context variable and execute every time with "Default".
but if write fixe value, it's ok

Thank's for your answer.
Mickael
Zhen1
Contributor
Contributor

context.contextenv cann't be treated as a variable. It is treated as a constant.

So job find a context named "context.contextenv". While job can not find it in the subjob, subjob used context by default

zjing
Contributor III
Contributor III

context.contextenv cann't be treated as a variable. It is treated as a
constant.

So job find a context named "context.contextenv". While job can not find it
in the subjob, subjob used context by default



I hope it usful for you