Five Stars

How to execute a Job depending on an input row using tRunJob

Hi all,

 

I'm facing problems using tRunJob which takes me to think that I'm completely wrong with an idea that seems simple.

 

My problem is that I want to read a table record by record and depending of the value of that record call one Job or another. I know I can do it using the trigger Run If, but I don't like it in this way because I'd have the same number of tRjunJob components in one Job as tables to be read (about 40).

What I want to do is to read a control table which tells me which one of that 40 tables I have to load. So, I need to read the first record of that control table and call the job related to the table I need to reload, read the second record of the control table and call de job related to that second table and so on. What I was thinking, it's once that I´ve read the first record, save in a context variable the name of the job I need to call, and pass that context variable to the component tRunJob to know which Job I need to call, but the problem is that in tRunJob I have to choose exactly which Job to call instead of passing the name of the Job I want to call (choosing Use dynamic job option forces me to choose an expecific Job). Is there any way to do it in this way instead of using Run If as many times as number of tables?

 

This is driving me crazy Smiley Frustrated

 

Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: How to execute a Job depending on an input row using tRunJob

Hi
If you are using enterprise subscription product, you can use the 'dynamic job' feature on trunJob, you just need one trunJob to call the child job dynamically based on the value of a context variable, the job design looks like:
tmysqlinput--main(row1)--tFlowToiterate--tjava--oncomponentok--trunJob

on tjava:
if (row1.columnName.equals("table1")){
context.childJobName="callTable1";}
else if (row1.columnName.equals("table2")){
context.childJobName="callTable2";}
else if .....

 

on tRunJob, check the 'dynamic job' option and select all the jobs which might be called during the job execution.



Regards
Shong

----------------------------------------------------------
Talend | Data Agility for Modern Business
7 REPLIES
Eight Stars

Re: How to execute a Job depending on an input row using tRunJob

Had the same problem... however, think outside the box!
Generate your nTable jobs independently.
tSystem -> <runYourgenerated.sh>
Community Manager

Re: How to execute a Job depending on an input row using tRunJob

Hi
If you are using enterprise subscription product, you can use the 'dynamic job' feature on trunJob, you just need one trunJob to call the child job dynamically based on the value of a context variable, the job design looks like:
tmysqlinput--main(row1)--tFlowToiterate--tjava--oncomponentok--trunJob

on tjava:
if (row1.columnName.equals("table1")){
context.childJobName="callTable1";}
else if (row1.columnName.equals("table2")){
context.childJobName="callTable2";}
else if .....

 

on tRunJob, check the 'dynamic job' option and select all the jobs which might be called during the job execution.



Regards
Shong

----------------------------------------------------------
Talend | Data Agility for Modern Business
Five Stars

Re: How to execute a Job depending on an input row using tRunJob

Thanks both of you!

 

I'll try the ways you say. I'm using the Open Source version (7.0.1) of Talend DI, so I think tJava could help if the option 'Dynamic job' of tRunJob is just available for the Enterprise version. I'll come back here even if it works or not.

 

Regards

Five Stars

Re: How to execute a Job depending on an input row using tRunJob

Hi Shong,

 

The flow I had, it was the same as yours with a filter component and a sort component between tdbinput and tFlowToIterate (essentially the same), but what about instead the If logic on tJava, just something like this?

 

context.JobName=row1.output; where row1.output returns the name of the job to be passed to tRunJob (we have a table with that relation table-job to be executed).

 

Despite not having the enterprise product, I've been able to use the option 'Use Dynamic Job' on tRunJob, setting context Job to context.JobName and selecting all de jobs that could be executed in 'Jobs' and it runs the job I wanted with that context variable (which it's actualized in each iteration). Does it make sense to you?

 

Regards!

Eight Stars

Re: How to execute a Job depending on an input row using tRunJob

Thankyou for the kudos and thankyou for posting, I overlooked this checkbox ... I dont know how many years its there, honestly I have no clue... but ... oh boy ... my nodejs config is really coming into place now... im using a json with jobconfigs to run my jobs, if you want I can share send me a privatemsg.

Happy me!

Five Stars

Re: How to execute a Job depending on an input row using tRunJob

Hi Dijke,

 

I'm glad this post helped you. I think our designs have nothing in common but I couldn't believe no one had faced the same problem as me!

I've finally achieved what I needed using the option 'Use Dynamic Job' in tRunJob preciding by a tJava.

 

Regards.

Five Stars

Re: How to execute a Job depending on an input row using tRunJob

Hi Shong,

 

one question. Why between tJava an tRunJob you use On component ok instead of Main or Iterate? I don't see the difference here, at least between Main and On component ok.