﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="scheduler.xsl" type="text/xsl"?>

<!--$Id: job.xml 3623 2005-04-20 06:53:16Z jz $-->

<description 
    title    = "What is a Job?" 
    base_dir = ""
    author   = "$Author: aa $"
    date     = "$Date: 2007-10-10 20:13:31 +0200 (Mi, 10 Okt 2007) $"
>
    <scheduler_keyword keyword="Job"/>
    
    A job determines the program to be executed, its run time and 
    what is to be done in the event of an error occurring.
    Further, any parameters to be used, pre and post processing, 
    locks preventing simultaneous access to a file and possible follow-on jobs may 
    also belong to a job configuration.
    <br/><br/>
    A Job is defined in the XML configuration using <b><scheduler_element name="job"/></b>.
<!--Ein Job bestimmt das auszuführende Programm, seine Laufzeit und das Verhalten im Fehlerfall.
    Darüber hinaus können die Parametrisierung, Vor- und Nachverarbeitung,
    konkurrierender Zugriff auf Sperren und mögliche Folge-Jobs Teil einer Job-Konfiguration sein.
    <br/><br/>
    Ein Job wird definiert in der XML-Konfiguration mit <b><scheduler_element name="job"/></b>.-->
    
    
    
    <h2>Job Configuration</h2>
<!--<h2>Konfiguration</h2>-->
    
    <p>
        The <scheduler_element name="job">XML configuration of a job</scheduler_element>
        can be carried out in the central start configuration file, 
        (which is usually <code>./config/scheduler.xml</code>) or in a separate configuration file 
        in the configuration directory which is monitored by the Job Scheduler
        (usually <code>./config/live</code>) - see also <scheduler_a href="dynamic_configuration.xml"/>
    <!--Die <scheduler_element name="job">XML-Konfiguration eines Jobs</scheduler_element>
        kann in der zentralen Startkonfigurationsdatei 
        (meist <code>./config/scheduler.xml</code>) oder in Form einer separaten Datei
        in dem vom Job Scheduler überwachten Konfigurationsverzeichnis (meist <code>./config/live</code>)
        vorgenommen werden, siehe <scheduler_a href="dynamic_configuration.xml"/>-->
    </p>
    
    
    
    <h2>Implementation</h2>
<!--<h2>Implementierung</h2>-->
    <p>
        The Job Scheduler starts executable programs and can start
        individually implemented jobs, which use the Job Scheduler's API.
    <!--Der Job Scheduler startet ausführbare Programme und kann
        Jobs mit individuellen Implementierungen starten, die das 
        API des Job Schedulers nutzen.-->
    </p>
    
    
    <p><b>Executable Programs</b></p>
<!--<p><b>Ausführbare Programme</b></p>-->
    <div class="indent">
        <p>
            Executable programs may be implemented as
        		<i>executable</i>, <i>shell scripts</i> or as <i>batch files</i>.
        		This includes programs, 
        		such as JavaScript, VBScript, Perl, PHP, Ruby etc.
        		for which an interpreter needs to be started with the executable program file,
        		Java classes can be started using the Java Virtual Machine (JVM) configured 
        		for the Job Scheduler.
        <!--Sie können beliebig implementiert sein als
        		<i>executable</i>, <i>shell scripte</i>, <i>batch files</i>.
        		Dies bezieht Programme ein, 
        		z.B. JavaScript, VBScript, Perl, PHP, Ruby etc., 
        		für die ggf. ein Interpreter mit der auszuführenden Programmdatei gestartet werden muss.
        		Java-Klassen können mit der für den Job Scheduler konfigurierten JVM gestartet werden.-->
    		</p>
    		<p>
        		Executable programs can be configured using the following elements:
        <!--Ausführbare Programme können mit folgenden Elementen konfiguriert werden:-->
        		<br/><br/>
        		<p><b><scheduler_element name="script" attribute="language"/></b></p>
        		<br/>
        	  <div class="indent">
            		<p><scheduler_element name="script" attribute="language">&lt;script language="shell"&gt;</scheduler_element></p>
            		<div class="indent">
        						<p>
        								The Job Scheduler creates a shell for the execution of the program. 
        						<!--Der Job Scheduler erzeugt eine Shell für die Ausführung des Programms. -->
        						</p>
        						<p>
        				    		<u>Example:</u>
        				    <!--<u>Beispiele:</u>-->
<pre>&lt;job name="simple_shell"&gt;
  &lt;script language="shell"&gt;&lt;![CDATA[
    echo hello world
    call my_script.cmd
    my_prog.exe
  ]]&gt;&lt;/script&gt;
&lt;/job&gt;  

&lt;job name="simple_command"&gt;
  &lt;script language="shell"&gt;
    &lt;include file="my_script.cmd"/&gt;
  &lt;/script&gt;
&lt;/job&gt;</pre>
        								Commands for the command line can be directly included as content of the <code>&lt;script&gt;</code>
        								elements. Alternatively, shell scripts can be specified using <code>&lt;include&gt;</code>.
        						<!--Kommandos des Kommandozeileninterpreters können direkt als Inhalt des <code>&lt;script&gt;</code>
        								Elements einngegeben werden. Alternativ können Shell Scripte mittels <code>&lt;include&gt;</code>
        								angegeben werden.-->
        						</p>
        				</div>
        				
            		<p><scheduler_element name="script" attribute="language">&lt;script language="java"&gt;</scheduler_element></p>
            		<div class="indent">
        						<p>
        								The Job Scheduler starts a JVM for the execution of the Java class. 
        						<!--Der Job Scheduler startet eine JVM für die Ausführung der Java-Klasse. -->
        						</p>
        						<p>
        				    		<u>Example:</u>
        				    <!--<u>Beispiel:</u>-->
<pre>&lt;job name="simple_java"&gt;
  &lt;script language   = "java" 
          java_class = "sos.scheduler.ftp.JobSchedulerFTPReceive"/&gt;
&lt;/job&gt;</pre>
                		</p>
                </div>
        		</div>

        		<p><b><scheduler_element name="process" attribute="file"/></b></p>
        		<br/>
        	  <div class="indent">
        				<p>
        				    The Job Scheduler starts the program without a separate shell.
        				<!--Der Job Scheduler startet das Programm ohne separate Shell.-->
        				</p>
        				<p>
        						<u>Example:</u>
        				<!--<u>Beispiele:</u>-->
<pre>&lt;job name="simple_job"&gt;
  &lt;process file="c:\my_prog.exe"/&gt;
&lt;/job&gt;

&lt;job name="interpreter_job"&gt;
  &lt;process file="c:\php\php.exe"
           param="-f 'c:\test\phpinfo.php'"/&gt;
&lt;/job&gt;</pre>
                    Inhterpreting programmes must be configured as the executing programmes for programme files,
                    which are to be started per interpreter.
                <!--Für Programmdateien, die per Interpreter gestartet werden, muss dieser als auszuführendes Programm
                    konfiguriert sein.-->
        				</p>
        		</div>
    		</p>
    </div>
    
    
    <p><b>Implementation with the Job Scheduler API</b></p>
<!--<p><b>Implementierungen mit dem Job Scheduler API</b></p>-->
    <div class="indent">
      <p>
         Job implementations can use the Job Scheduler API - for example for
         logging, informing per e-mail, calling job, task and order objects, etc.
     <!--Job-Implementierungen können das API des Job Schedulers nutzen,
         z.B. zur Protokollierung, Benachrichtigung per eMail, Zugriff auf
         Job-, Task- und Auftragsobjekte etc.-->
      </p>
      <p>
         The Job Scheduler does not start these scrips per interpreter (see above)
         but instead makes use of a sub-programme interface that is provided by the respective the script language.
         The Job Scheduler then makes the objects and methods of its API available to such languages.
     <!--Der Job Scheduler startet diese Scripte nicht per Interpreter (s.o.) sondern
         implementiert eine Unterprogrammschnittstelle für den Aufruf von Scripten
         in diesen Sprachen und stellt ihnen Objekte und Methoden zur Verfügung.-->
      </p>

      <p><b><a href="api/api-java.xml">Java</a></b></p>
      <div class="indent">
        <p>
           A Job implemented with the Java programming language inherits from the abstract class
           <a href="javadoc/sos/spooler/Job_impl.html">sos.spooler.Job_impl</a>. (see Javadocs for details).
       <!--Ein Job in Java ist eine Implementierung der abstrakten Oberklasse
           <a href="javadoc/sos/spooler/Job_impl.html">sos.spooler.Job_impl</a>.-->
        </p>
       <p>
           The <a href="javadoc/index.html">Java Interface</a> provides additional classes
           in the same manner as the COM, JavaScript and Perl interfaces.
           This allows the implementation of jobs in these languages.
       <!--Die <a href="javadoc/index.html">Java-Schnittstelle</a> stellt weitere Klassen bereit.
           Sie gilt entsprechend für die COM- und Perl-Schnittstellen, 
           wenn Sie Ihren Job in einer anderen Sprache implementieren.-->
       </p>
        <p>
           The address of the implemented class is specified in 
           <scheduler_ini_entry file="sos.ini" section="java" entry="class_path"/>.
       <!--Den Pfad der implementierten Klasse geben Sie in
           <scheduler_ini_entry file="sos.ini" section="java" entry="class_path"/>
           an.-->
        </p>
      </div>
 
      <p><b><a href="script_language_javascript.xml">JavaScript and JScript</a></b></p>
  <!--<p><b><a href="script_language_javascript.xml">JavaScript und JScript</a></b></p>-->
      <div class="indent">
        <p>
          JavaScript is available in the SpiderMonkey implementation (http://developer.mozilla.org/en/docs/SpiderMonkey)
          in the Job Scheduler installation package for all platforms.
      <!--JavaScript ist in der Implementierung von SpiderMonkey (http://developer.mozilla.org/en/docs/SpiderMonkey)
          im Auslieferungsumfang des Job Schedulers für alle Plattformen enthalten.-->
        </p>
        <p>
          Microsoft JScript is available on Windows platforms.
      <!--Microsoft JScript ist auf Windows Plattformen verfügbar.-->
        </p>
      </div>

      <p><b><a href="api/api-vbscript.xml">VBScript</a></b></p>
      <div class="indent">
        <p>
        <p>
          Microsoft VBScript is available on Windows platforms.
      <!--Microsoft VBScript ist auf Windows Plattformen verfügbar.-->
        </p>
        </p>
      </div>

      <p><b><a href="api/api-perl.xml">Perl</a></b></p>
      <div class="indent">
        <p>
          Perl is generally already installed on Unix platforms. 
          The Job Scheduler installation programme attempts to configure the sub-programme interface
          to an existing Perl installation.
      <!--Perl ist auf Unix-Plattformen i.d.R. vorinstalliert. Das Installationsprogramm
          des Job Schedulers versucht die Unterprogrammschnittstelle passend
          zur vorhandenen Perl Version zu installieren.-->
        </p>
        <p>
          A Perl implementation such as that from http://www.activestate.com,
          can be installed if required. 
      <!--Auf Windows-Plattformen kann eine Perl-Implementierung, z.B. von http://www.activestate.com,
          nachinstalliert werden. -->
        </p>
      </div>

      <p><b><scheduler_a href="job_com.xml">COM</scheduler_a></b></p>
      <div class="indent">
        <p>
            A job can be implemented in any program language as a COM-Server (for Windows). 
            Further information can be found in the section on <a href="job_com.xml">Spooler Scripts</a>.
        <!--Sie können auch (unter Windows) einen Job in jeder beliebigen Programmiersprache
            als COM-Server implementieren. 
            Weiteres siehe <a href="job_com.xml">hier</a>.-->
        </p>
      </div>
    </div>



    <h2>The Status of a Job</h2>
<!--<h2>Zustand eines Jobs</h2>-->

    <p>
        Jobs have one of the following statuses:
    <!--Ein Job ist in einem der folgenden Zustände:-->
    </p>
    
    <table cellspacing="0" cellpadding="0">
        <col valign="baseline" style="padding-top: 1ex"/>
        <col valign="baseline" style="padding-top: 1ex; padding-left: 2ex"/>
        
        <tr>
            <td><scheduler_keyword keyword="pending"/><code>pending</code></td>
            <td>
                No task is running. This is the starting status.
            <!--Keine Task läuft. Das ist der anfängliche Zustand.-->
            </td>
        </tr>
        <tr>
            <td><scheduler_keyword keyword="running"/><code>running</code></td>
            <td>
                At least one task is running.
            <!--Wenigstens eine Task läuft.-->
            </td>
        </tr>
        <tr>
            <td><scheduler_keyword keyword="stopping"/><code>stopping</code></td>
            <td>
                The job is stopping. The Job Scheduler will not start another task and all current tasks are being stopped.
                As soon as all tasks are stopped, the job status changes to <code>stopped</code>.
                <br/>
                See also the command: <scheduler_element name="modify_job" attribute="cmd" value="stop"/>.
            <!--Der Job stoppt. Der Scheduler startet keine weitere Task und die laufenden Tasks werden beendet.
                Sobald alle Tasks des Jobs beendet sind, wechselt der Job in den Zustand <code>stopped</code>.
                <br/>
                Siehe das Kommando <scheduler_element name="modify_job" attribute="cmd" value="stop"/>.-->
            </td>
        </tr>
        <tr>
            <td><scheduler_keyword keyword="stopped"/><code>stopped</code></td>
            <td>
                No tasks are running and no further tasks will be started by the Job Scheduler.
                <br/>
                See also the command: <scheduler_element name="modify_job" attribute="cmd" value="stop"/>.
            <!--Keine Task läuft und der Scheduler startet keine weitere Task.
                <br/>
                Siehe das Kommando <scheduler_element name="modify_job" attribute="cmd" value="stop"/>.-->
            </td>
        </tr>
        <tr>
            <td><scheduler_keyword keyword="read_error"/><code>read_error</code></td>
            <td>
                The <code>reread</code> command has caused an error 
                and the job is unusable as the program code cannot be read from the underlying file.
                <br/>
                See also the command: <scheduler_element name="modify_job" attribute="cmd" value="reread"/>.
            <!--Das Kommando <code>reread</code> hat zu einem Fehler geführt,
                und der Job ist unbrauchbar, weil der Programmcode nicht gelesen werden konnte.
                <br/>
                Siehe das Kommando <scheduler_element name="modify_job" attribute="cmd" value="reread"/>.-->
            </td>
        </tr>
        <tr>
            <td><scheduler_keyword keyword="error"/><code>error</code></td>
            <td>
                The Job Scheduler does not start any new tasks after an error has occurred.
            <!--Wenn eine Task mit Fehler geendet hat, startet der Scheduler keine weitere Task.-->
                <!--Der Aufruf <scheduler_method class="Job" property="error"/> liefert den Fehler.-->
            </td>
        </tr>
    </table>




    <h2>Changing the Status of a Job</h2>
<!--<h2>Zustand des Jobs ändern</h2>-->

    <p>
        The <scheduler_element name="modify_job"/> element is used to change the status of a job.
        The Job Scheduler has a built-in <scheduler_a href="http.xml">HTML interface</scheduler_a> 
        with provision for the necessary operations.
    <!--Mit dem Kommando <scheduler_element name="modify_job"/> können Sie den Zustand des Jobs ändern.
        Die eingebaute <scheduler_a href="http.xml">HTML-Oberfläche</scheduler_a> des Job Schedulers bietet hierfür die  entsprechenden Operationen an.-->
    </p>




    <h2>Starting a Task</h2>
<!--<h2>Eine Task starten</h2>-->

    <p>
        The <scheduler_element name="run_time"/> parameter is used in the configuration 
        to specify whether a task should be started once or repeatedly.
    <!--In der Konfiguration können Sie mit <scheduler_element name="run_time"/> einstellen, 
        dass eine Task einmal oder periodisch gestartet werden soll.-->
    </p>

    <p>
        Both the <scheduler_element name="start_job"/> and the 
        <scheduler_method class="Job" method="start"/> API method can be used to start a task.
    <!--Das Kommando <scheduler_element name="start_job"/> startet eine Task.
        ebenso die API-Methode <scheduler_method class="Job" method="start"/>.-->
    </p>


    <p>&#160;</p>
    
    <p>
        A task will start automatically when no other task is running and when one of the following conditions are true:
    <!--Eine Task wird automatisch gestartet, wenn noch keine Task läuft und eine der folgenden Bedingungen gilt.-->
    </p>
    <ul>
        <li>
            At the start of a <scheduler_element name="period"/>, 
            when <code>repeat=</code> or <code>single_start=</code> is specified in the period.
        <!--Zu Beginn einer <scheduler_element name="period"/>, 
            wenn in ihr <code>repeat=</code> oder <code>single_start=</code> angegeben ist.-->
        </li>
        <li>
            When a previous run set 
            <scheduler_method class="Task" property="repeat" access="write" java_signature="double"/>
            and the repeat time has been reached.
        <!--Wenn ein vorangehender Lauf 
            <scheduler_method class="Task" property="repeat" access="write" java_signature="double"/>
            gesetzt hat und die Zeit erreicht ist.-->
        </li>
        <li>
            When a previous run caused an error and 
            <scheduler_method class="Job" property="delay_after_error" access="write" java_signature="int, double"/>
            has ended.
        <!--Wenn ein vorangehender Lauf fehlerhaft war und 
            <scheduler_method class="Job" property="delay_after_error" access="write" java_signature="int, double"/>
            abgelaufen ist.-->
        </li>
        <li>
            When the interval after the end of the previous task defined in 
            <scheduler_element name="period" attribute="repeat"/> 
            has ended.
        <!--Wenn das mit
            <scheduler_element name="period" attribute="repeat"/> 
            angegebene Intervall nach dem Ende der zuletzt gelaufenen Task abgelaufen ist.-->
        </li>
        <li>
            When <a href="directory_watch.xml">directory monitoring</a>
            is active and a change occurs in the monitored directory.
        <!--Wenn die <a href="directory_watch.xml">Verzeichnisüberwachung</a>
            aktiv ist und das überwachte Verzeichnis geändert worden ist.-->
        </li>
    </ul>
    
    <p>
        In addition, a task will start when:
    <!--Außerdem startet eine Task-->
    </p>
    <ul>
        <li>
            An order for the job is present and the number of tasks running is less than that specified in
            <scheduler_element name="job" attribute="tasks"/>.
        <!--wenn ein Auftrag für den Job vorliegt, und noch nicht soviele Tasks laufen, wie mit
            <scheduler_element name="job" attribute="tasks"/> zugelassen.-->
        </li>
    </ul>

    <p>
        A task will only start when it has a start time (<code>at</code>) or:
    <!--Eine Task läuft aber nur an, wenn sie eine Startzeit (<code>at</code>) hat oder-->
    </p>
    <ul>
        <li>
            the job has not been stopped, 
        <!--der Job nicht gestoppt ist, -->
        </li>
        <li>
            a period for the current time is given, 
        <!--es eine Periode für die aktuelle Zeit gibt, -->
        </li>
        <li>
            and the 
            (<scheduler_method class="Job" property="delay_after_error" access="write" java_signature="int, double"/>) 
            delay after an error is not active. 
        <!--und die Verzögerung nach Fehler 
            (<scheduler_method class="Job" property="delay_after_error" access="write" java_signature="int, double"/>) 
            nicht wirkt. -->
        </li>
    </ul>

    <h2>Locks</h2>
<!--<h2>Sperren</h2>-->
    <p>
        Jobs can be given locks, in order to stop the simultaneous processing by two tasks.
        <!--See <scheduler_a href="lock.xml" quote="yes"/>.-->
    <!--Jobs können mit Sperren versehen werden, um den gleichzeitigen Lauf zweier Tasks zu verhindern.
        Siehe <scheduler_a href="lock.xml" quote="yes"/>.-->
    </p>


    <h2>Directory Monitoring</h2>
<!--<h2>Verzeichnisüberwachung</h2>-->

    <p>
        The scheduler can start a job when a change takes place in a monitored directory.
        Further details can be found in the chapter <a href="directory_watch.xml">Directory Monitoring</a>.
    <!--Der Job Scheduler kann einen Job bei Änderungen in einem Dateiverzeichnis starten.
        Näheres im Kapitel <a href="directory_watch.xml">Verzeichnisüberwachung</a>.-->
    </p>



    <h2>Monitor Scripts</h2>

    <p>
        A monitor script can be configured for a job . 
        The Job Scheduler calls the functions of this script at the beginning and end of a task
        and before and after the <scheduler_method class="Job_impl" method="spooler_process"/> methods.
    <!--Für einen Job kann ein Monitor Script konfiguriert werden. 
        Der Job Scheduler ruft Funktionen des Monitor Scripts  bei Start und Ende der Task auf
        sowie vor und nach der Methode <scheduler_method class="Job_impl" method="spooler_process"/>.-->
    </p>
    <p>
        The monitor can be defined using the <scheduler_element name="monitor"/> element.
    <!--Den Monitor bestimmen Sie mit <scheduler_element name="monitor"/>.-->
    </p>
    <p>
        <u>Example:</u><pre>
    <!--<u>Beispiel</u><pre>-->
        
&lt;job name  = "simple_ftp"
  &lt;params&gt;
    &lt;param name = "ftp_host"            value = "localhost"/&gt;
    &lt;param name = "ftp_user"            value = "anonymous"/&gt;
    &lt;param name = "ftp_password"        value = "anonymous"/&gt;
  &lt;/params&gt;

  &lt;script language   = "java" 
          java_class = "sos.scheduler.ftp.JobSchedulerFTPReceive"/&gt;

  &lt;monitor&gt;
    &lt;script language="javascript">&lt;![CDATA[<![CDATA[
      function spooler_task_before() { 
        var today = yy = mm = dd = "";
        today = new Date();
        yy = today.getYear() + 1900;
        mm = today.getMonth() + 1;
        dd = today.getDate();
        if (parseInt(mm) < 10) mm = "0" + mm;
        if (parseInt(dd) < 10) dd = "0" + dd;
        spooler_task.params.set_var("ftp_file_path", "^test_" + yy + "-" + mm + "-" + dd + "\.csv$" );
        return true;
      } 
    ]]>]]&gt;&lt;/script&gt;
  &lt;/monitor&gt;
&lt;/job&gt;</pre>
       The monitor script uses a standard job included with the Job Scheduler installation package to transfer a file per FTP.
       Thereby the job parameters for the name of the file to be transferred is dynamically created from the current date.
   <!--Das Monitor Script verwendet einen Standard-Job der Auslieferung für den FTP-Transfer einer Datei.
       Dabei wird der Job-Parameter für den Namen der zu übertragenden Datei dynamisch aus dem Tagesdatum zusammengesetzt.-->
    </p>


</description>

