Five Stars

[resolved] Changing context variable values for the same job

Hi,
I have a set of jobs that uses a single context variable. This context variable is defined in the 'Contexts' in the Repository tree and is inturn used by every job.
This context variable takes in the values of 0 or 1. As of now I have set it to 1.
I want to run the job as a .sh file and pass 0 or 1 to the context variable. How can I accomplish this? My idea was to use the jobs to the work of both '1' and '0' without having to recreate the jobs separately.
Also, I want the jobs to run with context variable = 1 at a specified time and the jobs to run with context variable = 0 at Another specified time
Note : I am using TOS
Any thoughts on this would be greatly appreciated
Thanks
Rathi
12 REPLIES
Five Stars

Re: [resolved] Changing context variable values for the same job

You can pass values at runtime by modifying the launch script, for example: -
--context_param myString="modified value"
This is not the most elegant approach, depending on what your trying to achieve.
You can run your Jobs within different "contexts" and also take other approaches to 'externalise' your context values.
However, to answer your question, this is the solution.
Five Stars

Re: [resolved] Changing context variable values for the same job

Thank you for the quick response.
I have complex stored procedures to which I have to pass these context variables. The procedures have been written to work for both 1 and 0. So I just write in talend "select * from myproc("+context.variable+")". Through this I can use a single job that uses a single procedure and hence, work for both 1 and 0. 
Will you please help me understand how do I  use different contexts for the select statement I have mentioned or maybe how to externalize it?
Thanks
Rathi
Five Stars

Re: [resolved] Changing context variable values for the same job

It sounds like this may me the correct approach for what you're trying to achieve.
For more information on Context externalisation, I'd read about implicit loading and the tLoadContext component.
Five Stars

Re: [resolved] Changing context variable values for the same job

Thank you.
As per my understanding, context externalization can be done when I run the job from talend, but, is it possible use it when I export the job and run it as a .sh file ?
 Also, my requirement is to also specify the time at which it should run daily. The job should run twice during the day with context.variable = 1 and run once in the night with context.variable = 0.
Any thoughts on this?
Thanks
Rathi
Five Stars

Re: [resolved] Changing context variable values for the same job

That is not correct. You can externalise when you export/build your Job.
To run your Job at specified times, you need a Job Scheduler. If you're using Open Studio, you can use cron on Unix/Linux or Windows scheduler. You can pass the context value (on cron, at least) directly from the scheduler as the last parameter in your .sh fils is "$@"
Five Stars

Re: [resolved] Changing context variable values for the same job

Hi,
I was trying to use tloadcontext in my requirement.
Like I said earlier, I have a set of jobs inked to each other. With tloadcontext I can pass the context value to the first job. How do I propagate the context value to the next set of jobs.
tloadcontext --> job1 --> job2 --> job3 -- etc
Note : job1, job2 etc are all individual jobs
Thanks
Rathi
Five Stars

Re: [resolved] Changing context variable values for the same job

There's a checkbox on tRunJob that allows you to "transmit" context
Five Stars

Re: [resolved] Changing context variable values for the same job

That's great tal00000. Thank you.
But I am not using trunjob, I have just linked all jobs sequentially under a single job. Can I get it to work here?
Thanks
Rathi
Five Stars

Re: [resolved] Changing context variable values for the same job

Then you are using tRunJob.
If one Job calls another, then it is using the tRunJob component.
Five Stars

Re: [resolved] Changing context variable values for the same job

Hi ,
Please find below the job screenshot, I have linked one job to another.
Regards
Rathi
Five Stars

Re: [resolved] Changing context variable values for the same job

Exactly.
Each of these is an instance tRunJob.
Click on one and then look at the Component tab.
You will see that it is an instance of tRunJob.
You will also see the checkbox that says "Transmit whole context".
Five Stars

Re: [resolved] Changing context variable values for the same job

Got that !! Thank you tal00000..
Regards
Rathi