In this tutorial, we’ll go outside of the studio environment to show you how to set up your windows machine to run tasks outside of Talend Open Studio. We’ll create a simple task and then run it from a command line, then set a recurring task to do it daily.
Step 1: Create Job In Talend
To start off, simply add a tJava component into the canvas. This will be the only component in our job.
Secondly set up a local context variable in the context tab named “input”. Switch to “values as a table” and make the Default setting “standard”.
Lastly insert the following code into the tJava component. With the display code to check the value of context parameter input.
Save when everything is done.
Step 2: Export to Folder
Right click the job name in your repository and select “Build Job”.
Choose the location you want a zip file to be sent to. If you don’t have to move it anywhere else, select the “Extract the zip file” option. This will save the item and allow it to be runnable in the location specified. The “All” option downloads both a batch file for Windows and Shell file for Unix.
Step 3: Run on Command Line
In this demo we’ll be working with windows, but the unix commands are generally similar. Remember .bat is for windows and .sh is for unix.
Navigate to the location of the batch file in a command prompt and enter the command “<jobName>_run.bat”. The job shown here is simpledeploy, thus simpledeploy_run.bat. Note the text “Standard was called!”.
To change the context variable at run time, add it after the original command so:
“<jobName>_run.bat –context_param input=<not standard>”. Any value that is not “standard” will result in the text “Manual was called!”
Step 4: Schedule a Recurring Task
Many people will want to schedule their talend jobs as recurring tasks to run every day, week, etc. In unix, this can be done with a cron job, and in Windows we can use the Windows Scheduler application. Find this application and run it.
On the right side of the screen click “Create Basic Task”. Then select how often you want your task to run. Click Next.
Configure the exact nature of that task. Click Next.
Select the action “Start a program”. Click Next.
Browse to the location of the batch file. Enter any context parameter changed in the add arguments section. Click Next.
Review your choices and click Finish. Your task is scheduled.