tPrejob
Triggers a task required for the execution of a Job
tPrejob starts the execution of a
prejob.
tPrejob Standard properties
These properties are used to configure tPrejob running in the Standard Job framework.
The Standard
tPrejob component belongs to the Orchestration family.
The component in this framework is available in all Talend
products.
Global Variables
Global Variables |
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
tPrejob is a start component and |
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 |
For more information about the tPrejob component, see
Talend Studio User Guide.
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 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
-
With the main Job open on the design workspace, add a tPrejob, a tPostjob, a tFileDelete,
and two tFileCopy components to the
Job. -
Link the tPrejob component to the first
tFileCopy component using a Trigger > On Component
Ok connection to build the pre-job. -
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. - 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.
-
Double-click the tFileCopy component to
show its Basic settings view. -
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. -
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/. -
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.
-
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. -
Double-click the tFileCopy component to
open its Basic settings view. -
Fill the File Name field with the path
and filename of the backup file, D:/temp/backup-tempdata.csv in this example. -
In the Destination directory field,
specify or browse to destination directory, D:/temp/ in this example. -
Select the Rename check box, and specify
the orignal name of the temporary file in the Destination filename field, tempdata.csv. -
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 Finding duplicate files between two folders.
Related scenario
For another scenario that uses the tPrejob component,
see Creating a bar chart from the input data.