Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Attachment updated

Table of Contents

Introduction

You have installed the JobScheduler and started it. What comes next?
First Previous tutorials in this series have described the configuration and use of Order Jobs. However, there is another route to starting tasks with JobScheduler but first of all, a little background information ....
 
Excerpt Include
JobScheduler - Tutorial 1 - Running a simple job using the JOC Cockpit
JobScheduler - Tutorial 1 - Running a simple job using the JOC Cockpit
nopaneltrue
This tutorial is  intended to provide a quick and compact introduction to configuring and running Standalone Jobs on the JobScheduler.
A detailed step-by-step guide to configuring and running Order Jobs can be found in our previous Tutorials in this series.

Required Knowledge

Before you start to work through the examples in this document, we strongly recommend that you take the time to become familiar with some of the other JobScheduler documentation, in particular, the Installation and Configuration guide (scheduler_installation).
Note that a quick overview of the JobScheduler documentation (page 41) has been included at the end of this documentarticle. Status
title???

How are Jobs, Job Chains and Orders Configured?

  • JobScheduler objects (jobs, job chains, orders, schedules, process classes and locks) are all configured using plain XML files. These files are saved in the so-called Live Folder (the default location of this folder or directory is ./config/live, relative to the scheduler_data directory).
There is a file in this directory
  • The configuration for every JobScheduler
object and the configuration for the
  • object is saved individually in this
file
  • folder or one of its  sub-folders.
  • Changes to these object configuration files become effective without a restart of the JobScheduler being necessary, although on Unix® systems it may take up to a minute for a change to become effective.
  • Objects can be created and modified using JOE - JobScheduler Object Editor. New objects are
created
  • configureded by either
opening
  • duplicating an already existing
configuration file
  • object in JOE, and then modifying it
and then saving the file under a new name
  • , or by creating and configuring a completely new
file
  • object.
,

Other tutorials in this series

Configuring a Standalone Job

There are two ways to Configure the Standalone Job for this tutorial. Either:

  • follow the step-by-step instructions in this tutorial or
  • download and installing the completed configuration file.

Step-by-Step Configuration using the JobScheduler Object Editor

  1. Start JOE (the

Getting Started

  • Create a subdirectory named quickstart within the live folder (./config/live) directory. Jobs and job chains will be stored in this directory.
  • Start JOE (
    1. JobScheduler Object Editor) using one of the following scripts:
      • %SCHEDULER_HOME%\bin\jobeditor.cmd ( Windows™ )
      • $SCHEDULER_HOME/bin/jobeditor.sh ( Unix™ )
      • Once started JOE should look similar to the screenshot:
        Image Added
    2. Open the live folder in JOE:
      • Use the key combination ctrl+D
    to open the live folder in JOE .
    You can also open this dialog by selecting
      • or 
        select File -> Open
    Hot Folder from the
      • HotFolder from JOE's main menu or
    by clicking
      • click the red folder icon in the menu bar.
        The live folder should
    have been
      • be selected by default: if not, navigate to ./config/live.
    Select the quickstart sub-folder.
    If required you can also use this dialog to create the quickstart subdirectory.
    Image Removed
  • Open JOC  - the JobScheduler Operations Center.
    You can use JOC to follow changes to Jobs and other objects as they happen.
    You open JOC in a browser by entering the address http://[scheduler_host]:[scheduler_port], where [scheduler_host] and [scheduler_port] are the host name and the TCP port number of the JobScheduler (e.g. http://localhost:4444). Note that the JobScheduler must be running before JOC is called.
  • Setting up a Standalone Job

    Have you finished making the steps described in the Getting Started (page 6) section above? Then we can continue.

    The JobScheduler object tree is shown in the left hand pane of the screenshot below. Click on the Jobs element in this tree and then click on the   New Standalone Job  button in the right hand pane. A new Job will now be added. This will be shown in both the left hand element tree and the list of jobs in the main pane. Click on this new job.

    Image Removed

    This will open an empty Job configuration element as shown in the next screenshot. Give this job a name by entering, for example, firstJob in the Job Name field. Note that for a Standalone Job the Order Job: No radio button (to the right of the name) has to be selected. As already mentioned this setting is the key difference in between the configuration of a Standalone Job and that of an Order Job. In addition, this setting causes the Stop On Error checkbox to be activated (see also  Error Handling (page 32)). Now enter a shell script such as the following in the Source Code text field
      •  
      • Add a folder for your Standalone Jobs using the Make New Folder button as shown in the screenshot below: 
        Image Added

    1. Once the standalone-jobs folder configured in the previous step has been opened in JOE, click on the Jobs element in the left hand Scheduler Elements pane. This will open the Jobs panel as shown in the next screenshot:
       Image Added

    2. Now click on the New Standalone Job button to create a first job. This new Job, with Name job1, will be shown in both the Jobs and Scheduler Elements panes:
      Image Added
       
    3. Click on the job1 element in the Scheduler Elements pane to allow the Job to be configured as shown in the next screenshot:
      Image Added
      For the purposes of this tutorial we only need to configure:
      1. the Job Name and
      2. add a simple script using the code from one of the following code blocks, according to the operating system:

        Code Block
        languagexml
        titleExample Script: for Microsoft® Windows®
        @echo off
        echo  %SCHEDULER_JOB_NAME% is  running 
        echo  Current Timestamp:  %DATE% %TIME%
        exit 
    %ERRORLEVEL% 
      1. %ERRORLEVEL%
        Code Block
        languagexml
        titleExample Script: for Unix®
        #!/bin/sh
        echo  "$SCHEDULER_JOB_NAME is running"
        echo  "Current Timestamp:  `date`"
        exit $?

     

    Note that a Start Period (page 28) or Parameters can also be allocated to a  Job (page 22).

    Now save this configuration, either using the ctrl+S keys or File->Save, and JOE will create the ./config/live/quickstart/firstJob.job.xml file.

    Image Removed

    Now change to JOC and update the window using the  Update  button at the very top of the window. where you will now see the quickstart/firstJob Job in the Jobs tab. Click on the Job in the left hand part of the window to open a detailed view of the Job in the right hand part, as shown in the screenshot below. Start a task for this Job by clicking on ->Start task immediately  in the Job menu.

    Image Removed

    The task will now start to run and you can follow its progress in the Task history by clicking on the Show log button.

    Image Removed

    This will open a new browser window with the log output, where, amongst other things, you will be able to read the output from the shell script.

    Image Removed

      1. In addition, the Job has been given a Title, although this is not mandatory.
         
    1. The Job can now be saved using the Save Configuration icon near the top of the browser window.

    Downloading and Installing the Configuration File

    The Configuration file for the Standalone Job can be downloaded from jobscheduler-tutorials-6-standalone-job.zip.

    1. Unpack the .zip archive and copy the standalone-jobs folder and its contents to the JobScheduler's live folder. This will be one of the following directories:
      • C:\ProgramData\sos-berlin.com\jobscheduler\myJobSchedulerID\config\live ( Windows™ ) or
      • ~/sos-berlin.com/jobscheduler/myJobSchedulerID/config/live ( Unix™ )
      • Where myJobSchedulerID identifies the JobScheduler instance and is specified during installation.

    Running the Standalone Job

    1. Open the JOC Cockpit.
      You open JOC in a browser by entering the address such as http://localhost:4446/joc/ The exact address along with the account name and password you will require to log in will have been set by the system administrator that installed the JOC Cockpit.

    2. Once you have logged in to the JOC Cockpit you will see the Dashboard view, which presents an overview your system as shown in the next screenshot. 
      Image Added

    3. Change to the Jobs view by clicking on the button Jobs item in the main menu bar at the top of the window.
      Standalone Jobs - and their containing folders - are only visible in this view. This is in contrast to Order Jobs which are most often viewed in the Job Chains view.
      1. Click on the standalone_jobs folder in the tree menu to view the jobs in this folder.
        (If necessary first use the Expand All link to open the Live folder.)
    4. Start the Job using by selecting Start Task from the Job Card menu with the ellipsis symbol as shown in the next screenshot:
      Image Added
      1. Before the Job starts a Write a Comment form will open. Completion of this form may be mandatory, depending on the configuration of your JOC Cockpit. The default setting is that the completion is not mandatory.  
        Reasons entered with this form are added to the JOC Cockpit Audit Log. Reasons can be added for every change to the state of a JobScheduler object: changes of state include starting a task as here, terminating an Order, etc. See the JOC Cockpit - Audit Log Article for more information.
        Image Added

      2. Enter a reason: either standardized reasons can be selected from the selection offered when Pre-Defined Reason is selected or custom, when Individual Reason is selected, as shown. 
      3. When the Write a Comment form closes, the Task will start and Status element in the Job Card view may change from pending to running, depending on how quickly the job is completed.
    5. The History for the Job - i.e. the Task History for standalone jobs can be accessed in two ways. Either:
      1. In the Jobs view:
        1. Change to the Jobs List view using the button with the three horizontal bars at the very right of the View Header menu.
        2. Click on the 'test_sa_job1' link in the Job Name column of the list which will open the Job History as shown in the next screenshot:
          Image Added 
           
        3. The Log file for any given task in the History can now be opened by clicking on any one of the elements listed.

    Congratulations!

    You have successfully configured and run your first Standalone Job.

    Scheduled Job Starts

    As Order Jobs are started by Orders for a Job Chain, would it not be a good idea to set start times for Order Jobs? The answer is, "Yes" and, for this situation, the start times are set for the Order.

    In the following example a Standalone Job is configured to

    be started

    start daily at 12:00 o'clock and at 14:00.

    You will find the Run Time->Everyday function in the element tree in the left hand pane of JOE

    ,

    : this is a sub-element available for both Jobs and Orders. Use the New Period button (positioned on the right hand side) to add a new start period. Use the Apply Period button to save your input after you have selected Single Start  12:00:00 in the Start Time field. Repeat this procedure for Single Start 14:00:00.

    Image Removed

    Image Added

    Note that in addition to the fixed start times (Single Start), it is also possible to set the following starting modes:

    • repeat intervals (Interval end/start, Interval start/start).
    • run-time period when a Job is to be started outside of the Job's time period, the Job will be queued and started once its run-time period has been reached.
      Status
      titleTO CHECK

    Standalone Jobs can still be started manually, regardless of whether a start time or run period has been set. It is also possible to combine the scheduled starting of a Standalone Job with Directory Monitoring

    (page 26), which will be described in the next section

    .

    Status
    titleSCHEDULES HERE

    Directory Monitoring

    Starting a Standalone Job by Directory Monitoring

    With this method of operation, a standalone job is automatically started every time a file is either added to or deleted from a monitored directory. a filter can be specified to restrict the monitoring to specific file names.

    In the following example, the directory ./notification_dir will be monitored and only files with the extension txt will be acted on.

    Standalone Jobs that are started by directory monitoring can also be started manually as required. Directory monitoring can also be combined with Scheduled Starts (page 22).

    In the element tree in the left hand pane in JOE you will see under each job the Run Options function. Click on the New Dir button in the  Start When Directory Changed   area of the right hand pane to add the directory that is to be monitored. Save this configuration by clicking the   Apply Dir  button after you have entered the notification_dir and \.txt$ values in the Watch  Directory and File  Regex fields. Repeat this procedure to add further directories or patterns.

    Image Removed

    Status
    titleParameters

    Error Handling

    A Job ends in error when the script or program it calls returns an exit code other than 0. The Job will then be stopped, unless  Stop On Error (page 10) has been deactivated. Jobs that have been stopped are marked in red in the log in JOC.

    To illustrate this, change the scripts of the firstJob and firstOrderJob Jobs developed in the previous examples, so that they end in error.

    Code Block
    languagexml
    titleExample: Forcing an error using exit != 0
    ... exit 5

    Behavior of Stopped Standalone Jobs

    Stopped Standalone Jobs can be manually restarted in JOC using the Job menu->Start job immediately function. However they cannot be restarted automatically, either with a scheduled start or by directory monitoring. Use the function Job menu->Unstop in JOC to unstop a job.

    Error Handling for Standalone Jobs

    A Standalone Job can be configured to rerun after the Job has ended in error.

    8.4.1 Scheduled Repetition of a Standalone Job Ending in Error

    Select the Run Options function, which is a Job subelement in the JOE element tree. In the Delay After Error area you can use the NewDelay  button to specify a scheduled (delayed) restart of the Job. Enter, for example, values for Error Count and Delay of 2 and 00:00:10. Use the   Apply Delay  button to save these settings. Now repeat this procedure but enter an Error Count of 5 and check the stop radio button.

    Image Removed

    When the Job first ends in error, it will be immediately restarted. However, if the Job continues to end in error, after the 2nd rerun, the restart will only take place after a delay of 10 seconds and after the 5th attempt the Job will be stopped.

    Now start the Job in JOC, and look in the Task History, where the repeated job starts can be seen along with the delays they were subjected to.

    Image Removed

    Further Reading

    Configuration as XML

    The code used to specify the firstJob job at the times specified in schedule1 and with the Directory Monitoring also described is shown in the code block below:

    Code Block
    languagexml
    titleConfiguration of firstJob with Run Time
    collapsetrue
    <spooler>
      <config>
        <jobs>
          <job name="firstJob">
            <script language="shell"><![CDATA[@echo off
    echo  %SCHEDULER_JOB_NAME% is  running echo  Current Timestamp:  %DATE% %TIME%
    exit %ERRORLEVEL%]]></script>
            <run_time>
              <weekdays>
                <day day="1 2 3 4 5 6 7">
                  <period single_start="12:00" />
                  <period single_start="14:00" />
                </day>
              </weekdays>
            </run_time>
          </job>
        </jobs>
      </config>
    </spooler>

    Further References