Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The File Size Monitor can be configured from job or order parameters.
  • The following parameters are used:

    ParameterRequiredDefaultDescription
    monitor_file_change_locationyes The full path of a file that should be monitored.
    monitor_file_change_timeoutyes The max. duration in seconds that repeated checks for steady file size are performed.
    monitor_file_change_intervalno1Specifies the number of seconds that the monitor sleeps between repeated checks of the file size.
    monitor_file_change_exit_codeno 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_stateno Optionally sets the order to the specified state if the monitored file is not being found steady

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.

    Code Block
    languagexml
    titleJob Implementation Sample
    linenumberstrue
    collapsetrue
    <job  order="yes" stop_on_error="no">
        <script  language="shell">
            <![CDATA[
    echo hello world
            ]]>
        </script>
    
    
        <monitor.use  ordering="0" monitor="monitor_file_change"/>
    
    
        <run_time />
    </job>
  • Explanations

 

Monitor Implementation

  • s

    Code Block
    languagejs
    titleMonitor implementation
    linenumberstrue
    collapsetrue
    function spooler_process_before() {
    
        var rc = true;
    
        // merge parameters from task and order
        var params = spooler_task.params;
        params.merge( spooler_task.order.params );
    
        // required parameters
        var monitorLocation = params.value( 'monitor_file_change_location' );
        var monitorTimeout = params.value( 'monitor_file_change_timeout' );
    
        // optional parameters
        var monitorInterval = params.value( 'monitor_file_change_interval' );
        var monitorExitCode = params.value( 'monitor_file_change_exit_code' );
        var monitorErrorState = params.value( 'monitor_file_change_error_state' );
     
        if ( !monitorLocation ) {
            spooler_log.error( '.. parameter missing: monitor_file_change_location' );
            return false;
        }
    
        if ( !monitorTimeout ) {
            spooler_log.error( '.. parameter missing: monitor_file_change_timeout' );
            return false;
        } else {
            monitorTimeout = parseInt( monitorTimeout );
        }
    
        if ( !monitorInterval ) {
            monitorInterval = 1;
        } else {
            monitorInterval = parseInt( monitorInterval );
        }
    
        if ( !monitorExitCode ) {
            monitorExitCode = 1;
        } else {
            monitorExitCode = parseInt( monitorExitCode );
        }
    
        // let's use a Java package for file operations
        var monitorFile = new java.io.File( monitorLocation );
        if ( !monitorFile.isFile() ) {
            spooler_log.error( 'file does not exist: ' + monitorLocation );
            return false;
        } else {
            spooler_log.info( '.. monitoring file for max. ' + monitorTimeout + ' seconds: ' + monitorLocation );
        }
    
        var currentDuration = 0;
        var fileSize = 0;
        var lastFileSize = 0;
    
        do {
            lastFileSize = monitorFile.length();
            spooler_log.info( '.. current file size: ' + lastFileSize + ' bytes' );
            java.lang.Thread.sleep( monitorInterval * 1000 );
            fileSize = monitorFile.length();
            currentDuration = currentDuration + monitorInterval;
           } while ( (fileSize != lastFileSize) && (currentDuration < monitorTimeout) )
    
        if ( fileSize === lastFileSize ) {
            spooler_log.info( '.. file size is steady after ' + currentDuration + ' seconds (' + fileSize + ' bytes): ' + monitorLocation );
        } else {
            spooler_log.info( '.. giving up as file size is not steady after ' + currentDuration + ' seconds (' + fileSize + ' bytes): ' + monitorLocation );
            rc = false;
    
            if ( monitorExitCode ) {
                spooler_log.info( '.. setting task exit code: ' + monitorExitCode );
                spooler_task.exit_code = monitorExitCode;
            }
    
            if ( monitorErrorState ) {
                spooler_log.info( '.. moving order to error state: ' + monitorErrorState );
                spooler_task.order.state = monitorErrorState;
            }
        }
    
        return rc;
    }
  • xExplanations