Wednesday, January 18, 2017

Dynamic Subjobs in Talend

Introduction:

The major motive of this post is to walk you through how to achieve dynamic sub-jobs in Talend.

Steps to be followed:

Step 0 - Source data that contains Sub-job names

In our case,  let us have CSV file as input which contains sub-job names.


  JobName| Date
  ChildJob1| 1/16/2017
  ChildJob2| 1/17/2017
  ChildJob3| 1/16/2017


Requirement 1:-
  • Read jobName from a file and call the sub jobs dynamically.

Step 1 - Reading data from Source


Read the CSV file using tFileInputDelimited component and save the value of JobName in context variable in tJavaRow component.


If you notice, the "jobName" value is stored in context variable.

Step 2 - Defining dynamic sub-jobs 


Once the job names that need to be called dynamically are available in context variable, three actions to be done on tRunJob component.

      i. Enable Use dynamic job option
     ii. In Context job, enter the context variable name that holds the jobName.
    iii. In Job, select all the jobs that are dynamic sub-jobs.


If you notice, in the Job option, all the three sub jobs are selected.

The above will successfully achieve dynamic sub job.

Requirement 2:-
  • Read jobName and date from a file and call the sub jobs dynamically which has date as Today's date.
Follow Step 1, from above method.

Step 2: Check for Today's date condition


After component tFlowToIterate, place tJava component. In tJava component, compare the date value from row5 (output from tJavaRow componentwith Today's date like below


In tJava component, a small java code is written to get Today's date and compare that date with the date value coming from row5 and storing that comparison result in another context variable, named IsTodayJob, which is a Boolean type.

Step 3: Calling jobs which meet the condition


Once the comparison is done, the tRunJob component need to be triggered with "RunIf" mapping.

The "RunIf", should have context.IsTodayJob as condition like in below image.


Once this is done, tRunJob component should have three actions mentioned in Requirement 1.

Conclusion:

Component tRunJob supports dynamic job triggering from list of selected jobs.


~*~*~*~*The End~*~*~*~*