Scope
- A job should monitor the size of a file, e.g. a log file.
- If the file size is not steady after some predefined timeout then an error should be raised or a predefined order state should be set.
- File size monitoring is implemented by a Monitor script that can be used by any job.
Download and Installation
- Download: file_size_monitor.zip
- Unzip the archive to the
./config/live
folder of your JobScheduler Master.
Implementation
Configuration
- The File Size Monitor can be configured from job or order parameters.
The following parameters are used:
Parameter Required Default Description monitor_file_change_location
yes The full path of a file that should be monitored. monitor_file_change_timeout
yes The max. duration in seconds that repeated checks for steady file size are performed. monitor_file_change_interval
no 1 Specifies the number of seconds that the monitor sleeps between repeated checks of the file size. monitor_file_change_exit_code
no 1 Optionally sets the exit code of the current job to the specified value if the monitored files is not being found steady. This works for shell jobs exclusively. monitor_file_change_error_state
no Optionally sets the order to the specified state if the monitored file is not being found steady
Order Implementation
- An order can be used to carry the parameters for the File Size Monitor.
The order can be implemented like this:
Job Implementation
- A job that makes use of the File Size Monitor can reference the monitor by the
<monitor.use>
element. The job can be implemented as a shell job or as an API job for any of the supported languages, e.g.
- Explanations
- line 2 to 6: implements the job script
- line 8: references the monitor script
- Explanations
Monitor Implementation
The File Size Monitor is implemented as follows:
- Explanations
- line 1: the monitor implements the
spooler_process_before()
function, i.e. it is executed for orders (not for standalone jobs) before the order is processed by the associated job. - line 6-7: the monitor parameters are merged from task and order parameters. Precedence is granted to order parameters.
- line 10-16: parameters values are assigned to local variables.
- line 18-28: the required parameters are checked and an error is raised if parameters are missing.
- line 30-40: default values for optional parameters are assigned
- line 43-49: the monitor makes use of the Java
File
class as JavaScript does not provide file operations. Integrating Java with JavaScript works seemlessly as both are provided by the JVM. This integrations allows to use any Java classes from JavaScript. The monitor checks the existence of the monitored file and will raise an error if the file does not exist. - line 51-61: a loop is implemented that considers changes in the file size for the max. duration of repeated checks. Between checks a sleep interval is implemented.
- line 63-78: finally if the file size is found to be steady the respective informative message is written to the log and otherwise the return code is set accordingly.
- line 1: the monitor implements the
- Explanations
- x