tPrejob - 6.3

Talend Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

Function

tPrejob starts the execution of a prejob.

Purpose

tPrejob triggers a task required for the execution of a Job

tPrejob properties

Component family

Orchestration

 

Global Variables

ERROR_MESSAGE: the error message generated by the component when an error occurs. This is an After variable and it returns a string. This variable functions only if the Die on error check box is cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl + Space to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio User Guide.

Usage

tPrejob is a start component and can only be used with an iterate connection to the next component.

Connections

Outgoing links (from this component to another):

Trigger: On Component Ok.

Incoming links (from one component to this one):

Trigger: Synchronize; Parallelize.

For further information regarding connections, see Talend Studio User Guide.

Limitation

n/a

For more information about the tPrejob component, see Talend Studio User Guide.

Scenario: Handling files before and after the execution of a data Job

In this scenario, a pre-job and a post-job are added to the Job describes in Scenario 2: Finding duplicate files between two folders to handle files before and after the execution of the main data Job.

As described in the above-mentioned scenario, when the main data Job is started, it creates a temporary text file to store the fetched filenames. If the specified temporary file already exists, it will be overwritten.

To prevent possible loss of data, the pre-job saves a backup copy of the specified file by renaming it, if it exists, before the main Job is executed.

After the execution of the main data Job, the post-job deletes the temporary file created by the data Job and restores the backup file, if any.

Adding and linking components

  1. With the main Job open on the design workspace, add a tPrejob, a tPostjob, a tFileDelete, and two tFileCopy components to the Job.

  2. Link the tPrejob component to the first tFileCopy component using a Trigger > On Component Ok connection to build the pre-job.

  3. Link the tPostjob component the tFileDelete component using a Trigger > On Component Ok connection, and link the tFileDelete component to the other tFileCopy component to build the post-job.

  4. Label the relevant components to better identify their roles.

Configuring the components

Configuring the pre-job

In the pre-job, the tPrejob component does not have any parameter or property to configure; it just triggers the tFileCopy component before the execution of the main data Job to rename the specified file, so all the required configurations are made in the tFileCopy component.

  1. Double-click the tFileCopy component to show its Basic settings view.

  2. Fill the File Name field with the path and filename of the temporary text file to be renamed, D:/temp/tempdata.csv in this example.

  3. In the Destination directory field, specify or browse to destination directory. In this example, we will save the backup copy in the same directory, D:/temp/.

  4. Select the Rename check box, and specify the new filename in the Destination filename field, backup-tempdata.csv. Leave the other parameters as they are.

Configuring the post-job

In the post-job, the tPostjob component does not have any parameter or property to configure; it just triggers the tFileDelete component after the execution of the main data Job to delete the temporary file used to store the fetched filenames, which then triggers the tFileCopy component to name the backup file back to its original name.

  1. In the Basic settings view of the tFileDelete component, fill the File Name field with the path and filename of the temporary file to be deleted, D:/temp/tempdata.csv in this example, and leave the other parameters as they are.

  2. Double-click the tFileCopy component to open its Basic settings view.

  3. Fill the File Name field with the path and filename of the backup file, D:/temp/backup-tempdata.csv in this example.

  4. In the Destination directory field, specify or browse to destination directory, D:/temp/ in this example.

  5. Select the Rename check box, and specify the orignal name of the temporary file in the Destination filename field, tempdata.csv.

  6. Select the Remove source file check box to remove the backup file after the renaming action. Leave the other parameters as they are.

Expected execution result

If the specified temporary file exists, its data will be saved in a backup copy before the main data Job is executed and restored thereafter.

If the temporary file does not exist, the two tFileCopy components will generate an error, but this does not prevent the main data Job from being executed.

For the execution result of the main data Job, see Scenario 2: Finding duplicate files between two folders.

Related scenario

For another scenario that uses the tPrejob component, see Scenario: Creating a bar chart from the input data.