Built-in Jobs: Difference between revisions
| Line 52: | Line 52: | ||
** <code><ts:dateformat></code> corresponds to a timestamp formatted in the supplied SimpleDateFormat pattern (e.g. <code><ts:yyyy-MM-dd-HH-mm:ss></code>) | ** <code><ts:dateformat></code> corresponds to a timestamp formatted in the supplied SimpleDateFormat pattern (e.g. <code><ts:yyyy-MM-dd-HH-mm:ss></code>) | ||
** other literals outside of < or >, or inside of < and > but not matching any preceding tokens. | ** other literals outside of < or >, or inside of < and > but not matching any preceding tokens. | ||
** For example, to archive a GZIP version of a file with a timestamp with the extension 'gz', you can use the rename pattern | ** For example, to archive a GZIP version of a file with a timestamp with the extension 'gz', you can use the rename pattern <code><basename>.<ts:yyyy-MM-dd-HH-mm-ss>.<ext>.gz</code>. | ||
* ''Delete Original File (Boolean)'' - Should we remove the original file after archiving? | * ''Delete Original File (Boolean)'' - Should we remove the original file after archiving? | ||
* ''GZIP (Boolean)' - Should the target archive file be compressed using GZIP? | * ''GZIP (Boolean)' - Should the target archive file be compressed using GZIP? | ||
Revision as of 00:37, 22 April 2013
Obsidian comes bundled with free jobs for common tasks. These are provided in addition to Scripting Jobs to reduce implementation and testing time for common job functions.
File Processing Jobs
These jobs are provided to provide common basic file operations, such as file cleanup (deletion) and archiving. These jobs can be used to reduce the amount of code your organization needs to write.
File Cleanup Job
Job Class: com.carfey.ops.job.maint.FileCleanupJob
Introduced in version 2.0
This job deletes files in specified paths based on one or more file masks (using regular expressions).
It supports the following configuration options:
- Directory (1 or more Strings) - A directory to scan for files. If recursive processing is enabled, child directories are also scanned.
- File Mask (0 or more Strings) - A regular expression that files must match to be deleted. This is based on
java.util.regex.Pattern. To match all files, remove all configured values or use ".*" without quotes. If multiple values are used, files are eligible for deletion if they match any of the file masks. - Abort on Deletion Failure (Boolean) - If deletion fails, should we fail the job?
- File Size Minimum (String) - The minimum size in bytes a file must be to be deleted. File sizes can be specified in bytes, kilobytes, megabytes or gigabytes (e.g. 10b, 100kb, 20mb, 2gb).
- File Size Maximum (String) - The maximum size in bytes a file must be to be deleted. File sizes can be specified in bytes, kilobytes, megabytes or gigabytes (e.g. 10b, 100kb, 20mb, 2gb).
- Minimum Time Since Modified (String) - The minimum age of a file to be deleted, based on the modified time. This can be specified in seconds, minutes, hours and days (e.g. 10s, 5m, 24h, 2d).
- Recursive (Boolean) - Whether files in subdirectories of the configured directories should be checked for matching files.
Customization
If you wish to tweak or customize behaviour of this job, it can be subclassed. The following methods may be overridden or extended by calling super methods:
- onStart - Called on job startup.
- onEnd - Called on job end, regardless of success or failure.
- shouldDelete - Determines if a file should be deleted.
- deleteMatchingFile - Deletes a matching file and saves a job result for its path.
- matchesAge - Determines if a file matches any age conditions (i.e. Minimum Time Since Modified), or true if none are configured.
- matchesMask - Determines if a file matches any configured file masks, or true if none are configured.
- matchesSize - Determines if a file matches size conditions, or true if none are configured.
- processDirectory - Enumerates files in configured directories and calls shouldDelete and deleteMatchingFile as necessary.
File Archive Job
Job Class: com.carfey.ops.job.maint.FileArchiveJob
Introduced in version 2.0
This job archives files passed in via a chained job's saved results. Therefore, it is intended to be used as a chained job only. One or more accessible absolute file paths can be passed in via job results called 'file'. Each one will be processed for archiving. For example, if you have a job that generates two files called 'customers.txt' and 'orders.txt', you will use Context.saveJobResult(String, Object) to save a value for each absolute file path (e.g. 'C:/customers.txt' and 'C:/orders.txt').
It supports the following configuration options:
- Archive Directory (1 or more Strings) - A directory to where an archive copy is placed.
- Rename Pattern (String) - How should be name the archive file? Rename patterns support the following tokens delimited by < and >:
<filename>is the full original file name (e.g. 'abc.v1.txt')<basename>is the file with the last extension stripped (e.g. 'abc.v1')<ext>is the last file extension (e.g. 'txt')<ts:dateformat>corresponds to a timestamp formatted in the supplied SimpleDateFormat pattern (e.g.<ts:yyyy-MM-dd-HH-mm:ss>)- other literals outside of < or >, or inside of < and > but not matching any preceding tokens.
- For example, to archive a GZIP version of a file with a timestamp with the extension 'gz', you can use the rename pattern
<basename>.<ts:yyyy-MM-dd-HH-mm-ss>.<ext>.gz.
- Delete Original File (Boolean) - Should we remove the original file after archiving?
- GZIP (Boolean)' - Should the target archive file be compressed using GZIP?
- Overwrite Target File (Boolean) - If the archive file to be created already exists, should we overwrite it, or fail instead?
Customization
If you wish to tweak or customize behaviour of this job, it can be subclassed. The following methods may be overridden or extended by calling super methods:
- onStart - Called on job startup.
- onEnd - Called on job end, regardless of success or failure.
- determineArchiveFilename - Determines the name of the archive file based on the configured "Rename Pattern".
- processFile - For each input file, determines the archive file name and copies the original file to the archive.
- processDelete - If the original file is to be deleted, this method handles deleting the original file. If deletion fails, the job will fail, so if you wish to change his behaviour, you can override this method.
Maintenance Jobs
These jobs are provided to help maintain the Obsidian installation.
Job History Cleanup Job
Job Class: com.carfey.ops.job.maint.JobHistoryCleanupJob
This job will delete job history and related records beyond a configurable age in days. This is useful for keeping the database compact and clearing out old, unneeded data.
The value for maxAgeDays corresponds to the maximum age for records to retain. By default it is set to 365, but you may configure it to any desired value.
Note: We recommend high volume users schedule the job weekly or less frequently and to schedule it for a non-peak time.
Log Cleanup Job
Job Class: com.carfey.ops.job.maint.LogCleanupJob
This job will delete log database records beyond a configurable age in days. This is useful for keeping the database compact and clearing out old, unneeded data.
The value for maxAgeDays corresponds to the maximum age for records to retain. By default it is set to 365, but you may configure it to any desired value.
The value for level corresponds to the logging level of events to delete. You may specify multiple values, and the "ALL" option will result in all records matching the age setting being deleted. Valid levels to configure are: FATAL, ERROR, WARNING, INFO, DEBUG, and TRACE.
It is common to only delete lower severity level events, such as INFO, DEBUG, and TRACE, but retain higher severity messages.
Note: We recommend high volume users schedule the job weekly or less frequently and to schedule it for a non-peak time.