Menu

Post processing with SSH Job

Help
Naranek
2015-08-20
2015-08-21
  • Naranek

    Naranek - 2015-08-20

    Thanks for your help! I got the previous problem solved. I now have working SSH job, and I created another job where I parse data from the SSH job. It's working pretty well, but I can't seem to set the exit code for the job in javascript. The example at https://kb.sos-berlin.com/display/PKB/How+to+configure+the+handling+of+exit+codes+by+jobs uses spooler_task.set_exit_code( 0 ); but the api doesn't have that, but it has spooler_task.exit_code instead. I tried using that, but setting it seems to kill the whole order process. What's the right way to set the exit code in a job so that I can use the Job Chain controls (https://kb.sos-berlin.com/display/PKB/How+to+handle+exit+codes+in+a+job+chain) to control the flow.

    I also thought that it would be pretty cool if I could put the code from my parsing job into the SSH job's postprocessing step. I created a new Pre- / Post processor, copy&pasted my code from the next job there and changed the function name to spooler_task_after(), but when I run the order/job, my I don't see anything in the logs about the postprocessing being run. I also have the configuration monitor there, so the ordering="1" on this postprocessing. Am I on the right track here, and how could I get this working? It would basically cut the amount of jobs I need in half.

     
  • Andreas

    Andreas - 2015-08-21

    HI Naranek,

    sorry for the inconvenience: you were running into a compatibility problem of Java scripting engine versions.

    • The examples in the How to configure the handling of exit codes by jobs article have been using the <script language="javascript"> language.
      • For 32 bit JobScheduler releases this maps to the use of SpiderMonkey.
      • For 64 bit JobScheduler releases SpiderMonkey is not available.
    • We modified the examples in the above article to use the <script language="java:javascript"> language.
      • For Java versions before 1.8 this maps to the use of the scripting enginge Rhino.
      • For Java versions starting with 1.8 (which is required for JobScheduler releases starting from 1.9) this maps to the use of the scripting engine Nashorn.
      • Please consider the updated examples with changes such as
        • spooler_task_set_exit_code(0) becoming spooler_task.exit_code = 0
        • spooler_task.order().set_suspended(true) becoming spooler_task.order.suspended = true
    • The change of scripting languages in Java from version 1.7 to 1.8 requires some modifications of the script code. For details see What are the differences between the SpiderMonkey, Rhino and Nashorn scripting engines? article

    Best regards
    Andreas

     
  • Naranek

    Naranek - 2015-08-21

    Thanks for your help! I didn't realize that changing exit code isn't enough, but I have to change the state manually too. I'm still wondering why my post processor won't fire.

    This is my job:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <job  order="yes" stop_on_error="no" name="return test">
        <params />
    
        <script  language="java:javascript">
            <![CDATA[
    function spooler_process(){
        spooler_log.info("Exit code 10");
        spooler_task.exit_code = 10;
        var next_state = spooler_task.order.job_chain_node.next_state;
        spooler_log.info("order state changed to " + next_state);
        spooler_task.order.state = next_state;
    }
            ]]>
        </script>
    
        <monitor  name="process0" ordering="0">
            <script  language="java:javascript">
                <![CDATA[
    function spooler_task_after(){
    
        spooler_log.info("Exit code 5");
        spooler_task.exit_code =5;
        var next_state = spooler_task.order.job_chain_node.next_state;
        spooler_log.info("order state changed to " + next_state);
        spooler_task.order.state = next_state;
    
    }
                ]]>
            </script>
        </monitor>
    
        <run_time />
    </job>
    

    After running the messages from main script is run and exit code changes, but it seems like the monitor is completely ignored. I'm running this in a job chain if it has any significance.

     

    Last edit: SOSMP 2015-08-21
  • Andreas

    Andreas - 2015-08-21

    Hi Naranek,

    the functional code is fine. However, you should consider in which context this monitor script should be executed:

    • Have a look at the API docs on monitors
    • The function spooler_task_after() is executed after a task terminates.
      • This happens with a delay of 5s for tasks in job chains that do not run additional orders.
      • Additional <job idle_timeout="..." min_tasks="..."> settings can be used to prevent a task from terminating which is used in order to save the overhead of re-starting a job (and re-loading the JVM) for subsequent orders that arrive in short intervals.
    • The function spooler_process_after( spooler_process_result ) is executed after the order leaves the spooler_process() function. Don't forget to make this function return the value of the argument spooler_process_result or a boolean value that you calculate in the monitor script. This function might be more applicable for your case.

    Best regards
    Andreas

     

Log in to post a comment.