Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor corrections to text, page formatted

Table of Contents

Introduction - PHP XML Interface

Question: How to communicate with JobScheduler from PHP scripts e.g. to add jobs.Downloads:

This example describes how you can start jobs, add orders to job chains by your application. The examples are written in PHP.

Downloads

...

Instructions

...

  • Unzip package_scheduler.zip to folder package in your web folder .
  • Unzip package_class.zip to folder package in your web folder


How it works

...

JobScheduler – Program Interface

 

This document describes how applications can communicate with the JobScheduler. Possible tasks could be as follows:

 

  • Temporary creation of jobs
  • Starting jobs
  • Adding jobs
  • Changing runtime
  • Etc.

...

The communication is explained by the means of PHP examples. However you can use any other programming language of your choice.

 

Communication

...

The communication with JobScheduler takes place via TCP, where XML commands are transmitted. You can check the documentation for the possible XML commands: http://www.sos-berlin.com/doc/en/scheduler.doc/index.xml 

Note: All changes, which are made using the xml-commands vie TCP-communication are not persistent. E.g. added jobs are no longer available after restarting the JobScheduler

Example

...

Adding of a job with the name myJob. The Job runs once a day at 6pm and lists the table c:\temp.

Code Block
            <add_jobs>
              <job name="myJob"
                   title = "my first job">
                <script language="shell">
                <![CDATA[
                    dir c:\temp
                ]]>
                </script>
                <run_time>
                   <period single_start="18:00"/>
                </run_time>
              </job>
           </add_jobs>

...

 

Example with Telnet

telnet localhost 4454

The following XML string can be send e.g. via Telnet 

(The JobScheduler receives commands) 

Code Block
        <add_jobs>
          <job name="myJob" title = "my first job">
            <script language="shell">
            <![CDATA[dir c:\temp  ]]>
            </script>  <run_time>
            <period single_start="18:00"/>
            </run_time>
          </job>
        </add_jobs>

...

(The JobScheduler answers)

Code Block
 

...

        <?xml version="1.0" encoding="ISO-8859-1"?>
        <spooler>
          <answer time="2008-04-08 15:50:33.536">
            <ok/>
         </answer>
        </spooler>

...

 

Example with PHP Socket Communication (@fsockopen)

 

...

Code Block
languagephp
linenumberstrue
       //open

...

 Socket
      $socket = fsockopen("localhost", "4454", $errno,$errstr, 60);

...

 

...



      //build

...

 command

      $cmd = '<add_jobs><job name="myJob" title = "my first job"> <script';

...


      $cmd += 'language="shell"

...

>  <![CDATA[dir c:\

...

temp  ]]

...

>  </script>

...

 ';     
      $cmd += '<run_time> <period

...

 ';     
      $cdm += 'single_start="18:00"/></run_time></job></add_jobs>';

...

 

...



       //send

...

 command
      fputs( $socket, $cmd );

...

 

...



      //

...

Close Socket
      fclose( $socket);

...





After the JobScheduler has answered, you can view the Job in the Web GUI of the JobSchedulerJobScheduler's web interface, JOC.

Image Removed 

Evaluate Answer

 

The following function delivers the JobSchedulers JobScheduler's answers in one a single string. The JobScheduler delivers the answer via the same socket , that as was previously used during fputs, e.g. the answer can also be delivered directly after fputs.

 

...

Code Block
languagephp
linenumberstrue
       function get_answer($socket)

...

 {
       $answer = ''; $s = '';

...


       while ( !ereg("</spooler>", $s) && !ereg("<ok[/]?>", $s) )

...

 {
         $s = fgets($socket, 1000);

...

         

...



         if (strlen($s) == 0) { break;

...

         $answer .= $s;

...

 }
         $answer .= $s;
         $s = substr($answer, strlen($answer)-20);

...

 

...




         // chr(0) am Ende entfernen.

...


         if (substr($answer, -1) == chr(0))

...

 {
           $answer = substr($answer, 0, -1);

...

           break;

...

         }

...

       }

...

       $answer = trim($answer);

...

 

...

       return $answer;

...

     }

           break;
         }
       }
       $answer = trim($answer);

       return $answer;
     }

 

Communication with PHP Classes

...

For an application that sends commands to the JobScheduler it is very usefull to have a proper error handling. Apart from that, a higher level of abstraction is useful for understanding the source code. For this reason SOS GmbH offers a class for processing the communication. The class encapsulates the socket calls and provides a method for reading XML answers of the JobScheduler.

Installation

  • In your web directory set up a file called: packages.

...

 

...

  • In your application program include the class with:
    require_once( 'scheduler/sos_scheduler_command.inc.php');

Example

The example can be realized with these classes as follows:

 

...

Code Block
languagephp
linenumberstrue
//open socket

...


$command = new SOS_Scheduler_Command(‘localhost’,4454, 60);

...

 

...


//build command

...


$cmd = '<add_jobs><job name="myJob" title = "my first job"> <script';

...


$cmd += 'language="shell"

...

>  <![CDATA[dir c:\

...

temp  ]]

...

>  </script> ';

...


$cmd += '<run_time> <period ';

...


$cdm += 'single_start="18:00"/></run_time></job></add_jobs>';

...

 

...


if (!$command-

...

>connect())

...

 {
echo$get_error(). __FILE__ . __LINE__ ;

...


return 0;

...

     }

...

   

...


}
//send command

...


$this-

...

>command-

...

>command($cmd);

...

 

...


if ($command-

...

>get_answer_error())

...

 {
echo$command->get_error() .   . __FILE__ .   . __LINE__ ;

...

     }

...

 

...


}
//close socket

...


$command-

...

>disconnect();

 

 

Commands with xml-php Interface

...

  • One of the key tasks for the communication with JobScheduler is the creation of XML commands. To this end, you could use string functions or DOM classes

...

  • .
  • Another possibility is to use the xml-php-interface. The interface encapsulates the construction of XML commands and the communication with the JobScheduler. In this case the classes described in Communication with PHP Classes are used.

...

The advantage when of using these classes is the easy handling when assembling the XML data stream.

 

Within Within your application you have to setup the Include directory.

ini_set( 'include_path', 'packages' );

Example

The example with these classes is realized as follows: 

Code Block
languagephp
linenumberstrue
if(!defined('APP_SCHEDULER_HOST')) { define ( 'APP_SCHEDULER_HOST', 'localhost' ); }

...


if(!defined('APP_SCHEDULER_PORT')) {define( 'APP_SCHEDULER_PORT', '4454' ); }

...

 


//load missing classes and returns an object of the class

...


function &get_instance($class, $include_path='scheduler/', $extension='.inc.php') {

...


	if ( !class_exists($class) )

...

 {
		include( $include_path . strtolower($class) . $extension );

...

 }

...

 $object = new $class;

...


	}
	$object = new $class;
	$object->host=APP_SCHEDULER_HOST;

...


	$object-

...

>port=APP_SCHEDULER_PORT;

...

 

...

  return $object;   

...

}

...

 

...


	return $object;   
}
$job = &get_instance('SOS_Scheduler_Job','scheduler/');

...

 


//Setting some properties

...


$job->name           = "myJob";

...

$job->title          = "my first job ";

...

 

...

//Set the implentation

...


$job->title          = "my first job ";

//Set the implentation
$job->script('shell')-

...

>script_source='dir c:\

...

temp';

...

 


//The job has a runtime

...

 
$job-

...

>run_time()-

...

>period()-

...

>single_start = "18:00";

...

 

$job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');

...

 

...

 

...



if (! $job_command-

...

>add_jobs($job))

...

  {

...


	echo'error occurred adding job: ' . $job_command-

...

>get_error(); 
	exit; 
}

...

 

Example of Use

 

For the following examples it is assumed that this code is preceeding.

Code Block
languagephp
linenumberstrue
 

 

  1. if(!defined('APP_SCHEDULER_HOST')) { define ( 'APP_SCHEDULER_HOST', 'localhost' ); }
  2. if(!defined('APP_SCHEDULER_PORT')) { define ( 'APP_SCHEDULER_PORT', '4454' ); }
  3.  
  4. //load missing classes and returns an object of the class
  5. function &get_instance($class, $include_path='scheduler/', $extension='.inc.php') {
  6.    if ( !class_exists($class) ) {
  7.      include( $include_path . strtolower($class) . $extension );
  8.    }
  9.    $object = new $class;
  10.    $object->host=APP_SCHEDULER_HOST;
  11.    $object->port=APP_SCHEDULER_PORT;
  12.  
  13.    return $object;   
  14. } 

...

Adding a Order to a Job Chain

Code Block
languagephp
linenumberstrue
 

 

  1. //------------------------------------------------------------------------- 
  2. // How to add an order to an existing jobchain
  3. //-------------------------------------------------------------------------   
  4.  
  5. $order_launcher =
  6.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
  7.  
  8.  
  9. //Create an add_order object (SOS_Scheduler_Command_Add_Order).
  10.   $order = $order_launcher->add_order('jobchain',1);
  11.  
  12.  
  13. //Setting some properties of the order object
  14.   $order->id='sostest_12';
  15.   $order->replace="yes";
  16.   $order->priority="10"
  17.   $order->title="Testorder"
  18.   $order->web_service=""
  19.   $order->at="now+60";
  20.   $order->addParam('test','any value');
  21.  
  22. // Sending XML to the JobScheduler
  23.   if (!$order_launcher->execute($order)) {
  24.     echo 'error occurred adding order: '$order_launcher->get_error(); exit;
  25.  

 

...


Generated XML

Code Block
 


    <add_order
        at="now+60"
        id="sostest_12"
        job_chain="jobchain"
        priority="10"
        replace="yes"
        state="1"
        title="Testorder">
    <params>
    <param name="test" value="any value"/>
    </params>
    </add_order>
  

...

Remove an Order from a Job Chain

Code Block
languagephp
linenumberstrue
 

 

 

  1. //------------------------------------------------------------------------- 
  2. // How to add an order to an existing jobchain
  3. //-------------------------------------------------------------------------   
  4.  
  5. $order_launcher =
  6.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
  7.  
  8.  
  9. //Create an add_order object (SOS_Scheduler_Command_Add_Order).
  10.   $order = $order_launcher->add_order('jobchain',1);
  11.  
  12.  
  13. //Setting some properties of the order object
  14.   $order->id='sostest_12';
  15.   $order->replace="yes";
  16.   $order->priority="10"
  17.   $order->title="Testorder"
  18.   $order->web_service=""
  19.   $order->at="now+60";
  20.   $order->addParam('test','any value');
  21.  
  22. // Sending XML to the JobScheduler
  23.   if (!$order_launcher->execute($order)) {
  24.     echo 'error occurred adding order: '$order_launcher->get_error(); exit;
  25.   }
  26.  

 

...


Generated XML

Code Block
 
    <remove_order  order="sostest_13" job_chain="jobchain"/>

...

 

Change an Existing Order

Code Block
languagephp
linenumberstrue
 

 

 

  1. //------------------------------------------------------------------------
  2. //How to change an existing order
  3. //------------------------------------------------------------------------ 
  4.  
  5. //starting with adding an order.
  6. $order_launcher =
  7.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
  8.  
  9. $order = $order_launcher->add_order('jobchain',3);
  10. $order->replace='yes';
  11. $order->id='sostest_14';
  12. $order->run_time()->single_start="22:00";
  13.  
  14. if (!$order_launcher->execute($order)) {
  15.    echo 'error occurred adding order: ' . $order_launcher->get_error(); exit;
  16. }
  17.  
  18. //Now change the order.state
  19.  $order = $order_launcher->modify_order('jobchain','sostest_14');
  20.  $order->state=2;
  21.  if (!$order_launcher->execute($order)) {
  22.     echo 'error occurred modifying order: ' . $order_launcher->get_error(); exit;
  23.  } 

...

<modify_order  order="sostest_14" job_chain="jobchain" state="2"></modify_order>
Code Block
 

...

 

Start an Order with Submit

Code Block
languagephp
linenumberstrue
 

 

  1. //-----------------------------------------------------------------------
  2. // How to start an order with submit.
  3. // This can be usefull, when you know orders jobchain, id, state and starttime.
  4. //------------------------------------------------------------------------
  5.  
  6. $order_launcher =
  7.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
  8.  
  9. if (! $order_launcher->submit('jobchain','sostest_15',2,'now+30')) {
  10.   echo 'error occurred submitting order: ' . $order_launcher->get_error(); exit;
  11. }
  12.  

 

...


Generated XML

Code Block
 
    <add_order
      at="now+30"
      id="sostest_15"
      job_chain="jobchain"
      replace="yes"
      state="2">
    </add_order>
  

 

...

 

Adding a Job

Code Block
languagephp
linenumberstrue
 

 

  1. //------------------------------------------------------------------------
  2. // How to add a job
  3. //------------------------------------------------------------------------
  4.  
  5. $job = &get_instance('SOS_Scheduler_Job','scheduler/');
  6.  
  7.  
  8. //Setting some properties
  9. $job->force_idle_timeout   = "yes";
  10. $job->idle_timeout         = "1000";
  11. $job->ignore_signals       = "all";
  12. $job->java_options         = "java";
  13. $job->min_tasks            = "2";
  14. $job->name                 = "test_jobname3"
  15. $job->order                = "no";
  16. $job->priority             = "1" ;
  17. $job->stop_on_error        = "no";
  18. $job->tasks                = "4";
  19. $job->temporary            = "no"
  20. $job->timeout              = "10";
  21. $job->title                = "my job";
  22. $job->visible              = "yes"
  23.  
  24.  
  25.  
  26. //Defining some parameters
  27. $job->addParam('var1','value1');
  28. $job->addParam('var2','value2');
  29.  
  30.  
  31. //Set the implentation
  32. $job->script('javascript')->script_source='a=1;';
  33.  
  34.  
  35. //The job has a runtime
  36.  $job->run_time()->period()->single_start = "10:00";
  37.  $job->run_time()->period()->single_start = "11:00";
  38.  
  39.  $job->run_time()->at('2006-12-24 12:20');
  40.  $job->run_time()->at('2006-12-24 12:25');
  41.  $job->run_time()->at('2006-12-24 12:35');
  42.  
  43.  
  44.  /** A period forr day=1 */
  45.  $p = $job->run_time()->weekdays('1')->period();
  46.  $p->single_start = '07:30';
  47.  
  48.  $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
  49.  
  50.  
  51.  //First removing the job   
  52.  $job_command->remove($job->name);
  53.  if (! $job_command->add_jobs($job))  {
  54.   echo 'error occurred adding job: ' . $job_command->get_error(); exit;
  55.  

 

...


Generated XML

Code Block
 
    <job
      force_idle_timeout="yes"
      idle_timeout="1000"
      ignore_signals="all"
      java_options="java"
      min_tasks="2"
      name="test_jobname3"
      order="no"
      priority="1"
      stop_on_error="no"
      tasks="4"
      temporary="no"
      imeout="10"
      itle="my job"
      isible="yes">
    <params>
      param name="var1" value="value1"/>
      param name="var2" value="value2"/>
    </params>
    <script language="javascript">
      ![CDATA[a=1;]]></script>
    <run_time>
      period single_start="10:00"/>
      period single_start="11:00"/>
      at at="2006-12-24 12:20"/>
      at at="2006-12-24 12:25"/>
      at at="2006-12-24 12:35"/>
      weekdays>
        day day="1">
        period single_start="07:30"/>
        day>
      </weekdays>
    </run_time>
    </job>
  

 

...

 

Deleting a Job

Code Block
languagephp
linenumberstrue
 

 

 

  1. //------------------------------------------------------------------------       
  2. // How to to delete a job
  3. //------------------------------------------------------------------------ 
  4.  
  5. // First we add the job to have one, which we can remove
  6.   $job = &get_instance('SOS_Scheduler_Job','scheduler/');
  7.  
  8.   $job->name         = "jobtoberemoved";
  9.   $job->title        = "my removed job";
  10.   $job->visible      = "yes"
  11.  
  12.  
  13. //Set the implentation
  14.   $job->script('javascript')->script_source='a=1;';
  15.  
  16.   $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
  17.  
  18.   if (! $job_command->add_jobs($job)) {
  19.     echo 'error occurred adding job: ' . $job_command->get_error(); exit;
  20. }
  21.  
  22.  
  23. //Now the job will be removed
  24.   if (! $job_command->remove($job->name)) {
  25.      echo 'error occurred removing job: ' . $job_command->get_error(); exit;
  26.   } 

 

...


Generated XML

Code Block
 
    <job name="jobtoberemoved" tasks="1" temporary="no"
    title="my removed
    job" visible="yes">
    <script language="javascript">
    <![CDATA[a=1;]]>
    </script>
    </job>

    <modify_job job="jobtoberemoved" cmd="remove"/>
  

 

...

 

Starting a Job

Code Block
languagephp
linenumberstrue
 

 

 

  1. //------------------------------------------------------------------------
  2. //  How to Start a job
  3. //------------------------------------------------------------------------
  4.  
  5.  
  6. // First we add the job to have one, which we can start
  7.  
  8.  $job = &get_instance('SOS_Scheduler_Job','scheduler/');
  9.  $job->name             = "test_jobname3"
  10.  $job->title            = "my job";
  11.  $job->visible          = "yes"
  12.  
  13.  $job->script('javascript')->script_source='a=1';
  14.  
  15.  $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
  16.  
  17.  if (! $job_command->add_jobs($job))  {
  18.    echo 'error occurred adding job: ' . $job_command->get_error(); exit;
  19.   }
  20.  
  21.  if (! $job_command->start($name='test_jobname3', $start_at="now" )) {
  22.    echo 'error occurred submitting job: ' . $job_command->get_error(); exit;
  23.         }

 

...


Generated XML

Code Block
 


     start_job job="test_jobname3" at="now"></start_job>
 

...

Setting the runtime of a job

Code Block
languagephp
linenumberstrue
 

 

 

  1.   //-------------------------------------------------------------------
  2.   //  How to set the runtime of a job. Some examples
  3.   //-------------------------------------------------------------------
  4.   // First we add the job to have one, which we can start
  5.  
  6.   $job = &get_instance('SOS_Scheduler_Job','scheduler/');
  7.   $job->name                  = "test_jobname33"
  8.   $job->title                 = "test_jobname33";
  9.   $job->visible                 = "yes";   
  10.    
  11.   $job->script('javascript')->script_source='a=1';
  12.  
  13.   $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
  14.  
  15.   if (! $job_command->add_jobs($job))  { echo 'error occurred adding job: ' . $job_command->get_error(); exit; }
  16.  
  17.   //Start on the 28.st at 11:00
  18.   $job->run_time()->monthdays('28')->period()->single_start='11:00';
  19.  
  20.   //Adding a period
  21.   $period = new SOS_Scheduler_Runtime_Period();
  22.   $period->begin='12:00'; $period->end='13:00';
  23.   $period->repeat='60';
  24.   $job->run_time()->date('2006-30-11')->addPeriod($period);
  25.  
  26.   //starting at 11:00
  27.   $job->run_time()->at('11:00');
  28.   if (!$job_command->execute($job)) { echo 'error occurred : ' . $job_command->get_error(); exit; } 

 

...


Generated XML

Code Block
 


<job name="test_jobname33"
     tasks="1"
     title="test_jobname33"
     visible="yes">
<script language="javascript"><![CDATA[a=1]]></script>

<run_time>
<at at="11:00"/>
<date date="2006-30-11">
<period begin="12:00"
        end="13:00"
        repeat="60"/>
</date>
<monthdays>
       <day day="28">
          <period single_start="11:00"/>
       </day>
</monthdays>
</run_time>
</job>

 

...

Setting the runtime of an order

Code Block
languagephp
linenumberstrue
 

 

 

  1. //--------------------------------------------------------------
  2. //How to set the runtime of an order. Some examples
  3. //--------------------------------------------------------------
  4.  
  5. //adding an order with a runtime
  6.  
  7. $order_launcher = &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
  8. $order = $order_launcher->add_order('jobchain',3);
  9. $order->replace='yes';
  10. $order->id='sostest_14';
  11.  
  12. //Start on the 28.st at 11:00
  13. $order->run_time()->monthdays('28')->period()->single_start='12:00';
  14.  
  15. //Adding a period
  16. $period = new SOS_Scheduler_Runtime_Period();
  17. $period->begin='12:00'; $period->end='13:00';
  18. $period->repeat='60';
  19. $order->run_time()->ultimos('22')->addPeriod($period);
  20.  
  21. //starting at 11:00
  22. $order->at='2008-11-01 13:00';
  23.  
  24.  
  25. if (!$order_launcher->execute($order)) { echo 'error occurred adding order: ' . $order_launcher->get_error(); exit; } 

br>

...


Generated XML

Code Block
 


 <add_order
  at="2008-11-01 13:00"
  id="sostest_14"
  job_chain="jobchain"
  replace="yes"
  state="3">
<run_time>
   <monthdays>
     <day day="28">
       <period single_start="12:00"/>
    </day></monthdays>
    <ultimos>
      <day day="22">
       <period begin="12:00" end="13:00" repeat="60"/>
      </day>
    </ultimos>
</run_time>
</add_order>



...

Adding a Job to a hot folder

Code Block
languagephp
linenumberstrue
 

 

 

  1. // First we add the job to have one, which we can start
  2.  
  3.   $job = &get_instance('SOS_Scheduler_Job','scheduler/');
  4.   $job->name                  = "test_jobname77"
  5.   $job->title                 = "test_jobname77";
  6.   $job->visible                 = "yes";   
  7.    
  8.   $job->script('javascript')->script_source='a=1';
  9.  
  10.   $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');
  11.  
  12.   if (! $xml=$modify_hot_folder_command->store($job,"./test"))  { echo 'error occurred adding job: ' . $modify_hot_folder_command->get_error(); exit; }
  13.  

 

...


Generated XML

Code Block
 


 <modify_hot_folder folder="./test">
   <job name="test_jobname77" tasks="1" temporary="no" title="test_jobname77" visible="yes">
     <script language="javascript"><![CDATA[a=1]]></script>
   </job>
</modify_hot_folder>
  

...

Adding a Lock to a hot folder

Code Block
languagephp
linenumberstrue
 

 

 

  1. //--------------------------------------------------
  2.   //  How to add a lock to hot folder
  3.   //--------------------------------------------------
  4.   // First we add the lock to have one, which we can start
  5.   $lock = &get_instance('SOS_Scheduler_Lock','scheduler/');
  6.  
  7.   //Setting some properties
  8.   $lock->max_non_exclusive           = 1;
  9.   $lock->name="myLock";
  10.  
  11.    //Adding the lock to the hotfolder
  12.     $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');
  13.     if (! $xml=$modify_hot_folder_command->store($lock,"./test"))  { echo 'error occurred adding lock: ' . $modify_hot_folder_command->get_error(); exit; }
  14.  
  15.  

 

...


Generated XML

Code Block
 
<modify_hot_folder folder="./test">
  <lock name="myLock" max_non_exclusive="1"></lock>
</modify_hot_folder><br>
 

...

Adding a Process_class to a hot folder

Code Block
languagephp
linenumberstrue
 

 

 

  1. //-------------------------------------------------------------------------
  2.   //  How to add a process_class to hot folder
  3.   //-------------------------------------------------------------------------
  4.   // First we add the process_class to have one, which we can start
  5.   $process_class = &get_instance('SOS_Scheduler_Process_class','scheduler/');
  6.  
  7.   //Setting some properties
  8.   $process_class->max_processes           = 1;
  9.   $process_class->name=

 

...


Generated XML

Code Block
 
<modify_hot_folder folder="./test">
   <process_class
      name="myProcess_class"
      max_processes="1" replace="yes">
   </process_class>
 </modify_hot_folder>
  

...

Adding a Job_Chain to a hot folder

 

Code Block
languagephp
linenumberstrue
 

 

 

 

  1. //-------------------------------------------------------------
  2.   //  How to add a job_chain to hot folder
  3.   //-------------------------------------------------------------
  4.      $job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/');
  5.  
  6.    //Setting some properties
  7.      $job_chain->name           = "myJob_Chain";
  8.  
  9.  
  10.     //The job has a file_order_sources
  11.      $job_chain->file_order_source("/myDir","1");
  12.      $job_chain->file_order_source("/myOtherDir","2");
  13.  
  14.     //The job has a file_order_sinks
  15.      $job_chain->file_order_sink("6")  ->remove="yes";
  16.      $job_chain->file_order_sink("99") ->remove="yes";
  17.      $job_chain->file_order_sink("999")->remove="yes";
  18.  
  19.     //Adding some Job_chain_nodes
  20.      $job_chain->add_job("my_job1","1","2","99");
  21.      $job_chain->add_job("my_job2","2","3","99");
  22.      $job_chain->add_job("my_job3","3","4","99");
  23.      $job_chain->add_job("my_job4","4","5","999");
  24.      
  25.      //or adding a node
  26.      $job_chain_node = new SOS_Scheduler_Job_Chain_Node();
  27.  
  28.    //Setting some properties
  29.       $job_chain_node->state          = "5";  
  30.       $job_chain_node->error_state      = "99";    
  31.       $job_chain_node->next_state     = "6";    
  32.       $job_chain_node->on_error       = "suspend";
  33.       $job_chain_node->job              = "myJob5";
  34.    
  35.    //adding the node
  36.       $job_chain->add_node($job_chain_node);
  37.  
  38.  //Adding the job_chain to the hotfolder
  39.     $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');
  40.    if (! $xml=$modify_hot_folder_command->store($job_chain,"./test/chains"))  { echo 'error occurred adding job chain: ' . $modify_hot_folder_command->get_error(); exit; }
  41.  

 

...


Generated XML

Code Block
 


<modify_hot_folder folder="./test/chains">
  <job_chain name="myJob_Chain">
    <file_order_source directory="/myDir"/>
    <file_order_source directory="/myOtherDir"/>
    <file_order_sink state="6" remove="yes"/>
    <file_order_sink state="99" remove="yes"/>
    <file_order_sink state="999" remove="yes"/>
    <job_chain_node job="my_job1" state="1" next_state="2" error_state="99"/>
    <job_chain_node job="my_job2" state="2" next_state="3" error_state="99"/>
    <job_chain_node job="my_job3" state="3" next_state="4" error_state="99"/>
    <job_chain_node job="my_job4" state="4" next_state="5" error_state="999"/>
    <job_chain_node job="myJob5" state="5" next_state="6" error_state="99"/>
    </job_chain>
</modify_hot_folder>

  

...

Adding an Order to a hot folder

Code Block
languagephp
linenumberstrue
 

...

//-------------------------------------------------------------

...



  // How to add an order to a hot_folder

...



  //-------------------------------------------------------------

...

 

...



 

  $order_launcher = &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');

...

 

...



 

  //Create an order object (SOS_Scheduler_Command_Order).

...



  $order = $order_launcher-

...

>order('myJob_Chain',1);

...

 

...



 

  //Setting some properties of the order

...

 object

  $order-

...

>id='my_Order';

...



  $order-

...

>replace="yes";

...



  $order-

...

>priority="10";

...

 

  $order-

...

>title="Testorder";

...

 

  $order-

...

>web_service="";

...

 
  $order-

...

>at="now+60";

...


  $order-

...

>addParam('test','any value');

...

 

...



 

  //Adding the job_chain to the

...

 hotfolder

   $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');

...



   if (! $xml=$modify_hot_folder_command-

...

>store($order,"./test/chains"))

...

  { echo 'error occurred adding order: ' . $modify_hot_folder_command-

...

>get_error(); exit;

...

 } 




 

 

 

 

...

<modify_hot_folder folder="./test/chains">
<order  at="now+60" id="my_Order" job_chain="myJob_Chain" priority="10" replace="yes" state="1" title="Testorder">
<params>
<param name="test" value="any value"/>
</params>
</order>
</modify_hot_folder>

  

 

 

Adding a nested job chain to a hot folder

 

 
//-------------------------------------------------------------

 

 

// How to add an order to a

job_chain to a job_chain

hot_folder

 

 

//-------------------------------------------------------------

 

 

    $job

$order_

chain

launcher = &get_instance('SOS_Scheduler_

Job

OrderCommand_

Chain

Launcher','scheduler/');

 

 

 // First setting up two job_chains

//Create an order object (SOS_Scheduler_Command_Order).

 

 

 

//First job_chain     $job_chain->name           = "myJob_Chain"

$order = $order_launcher->order('myJob_Chain',1);

 

 

 

//

Adding some Job_chain_nodes

Setting some properties of the order object

 

   $job_chain->add_job("my_job1","1","50","99");

 

$order->id='my_Order';

 

 

$order->replace="yes";

 

 

$order->priority="10"

 

 

$order->title="Testorder"

 

 

$order->web_service=""

 

 

$order->at="now+60";

 

 

  •      $job_chain->add_job("my_job2","2","50","99");
  •  
  •     //Adding the endnodes
  •      $job_chain->add_end_node("99");
  •      $job_chain->add_end_node("50"

    $order->addParam('test','any value'

    );

     

     

    //Adding the job_chain to the hotfolder

     

     

    $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');

     

     

    if (! $xml=$modify_hot_folder_command->store(

    $job_chain

    $order,"./test/

    nested

    chains"))  {echo'error occurred adding

    job_chain

    order: ' . $modify_hot_folder_command->get_error(); exit; }

     

    ...

     

    ...

       //Second job_chain

    ...

        $next_job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/');

    ...

        $next_job_chain->name           = "myNext_Chain";

    ...

     

    ...

     

    ...

        //Adding some Job_chain_nodes

    ...

         $next_job_chain->add_job("my_job3","1","50","99");

    ...

         $next_job_chain->add_job("my_job4","2","50","99");

    ...

         

    ...

        //Adding the endnodes

    ...

         $next_job_chain->add_end_node("99");

    ...

         $next_job_chain->add_end_node("50");

    ...

       

    ...

     //Adding the job_chain to the hotfolder

    ...

        $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');

    ...

       if (! $xml=$modify_hot_folder_command->store($next_job_chain,"./test/nested"))  { echo 'error occurred adding job_chain: ' . $modify_hot_folder_command->get_error(); exit; }

    ...

     

    ...

     //Now creating a third job_chain which contains the first and the second.

    ...

        $nested_job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/');

    ...

        $nested_job_chain->name = "myNestedJob_Chain";

    ...

     

    ...

     //Adding the first nested job_chain.

    ...

        $job_chain_node = new SOS_Scheduler_Job_Chain_Node_Job_Chain("100");

    ...

     

    ...

       //Setting some properties

    ...

          $job_chain_node->state          = "100";    

    ...

          $job_chain_node->next_state       = "200";    

    ...

          $job_chain_node->error_state      = "1200";  

    ...

          $job_chain_node->job_chain      = "myJob_Chain";

    ...

        //Adding the job_chain_node to the job_chain;

    ...

          $nested_job_chain->add_node($job_chain_node);

    ...

     

    ...

        //Adding a second job_chain with -> add_job_chain();

    ...

        $nested_job_chain->add_job_chain("myNext_Chain","200","300","1200");

    ...

     

    ...

        //Adding the endnodes

    ...

          $nested_job_chain->add_end_node("1200");

    ...

          $nested_job_chain->add_end_node("300");

    ...

     

    ...

     

    ...

        //Adding the job_chain  to the hotfolder

    ...

         $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');

    ...

         if (! $xml=$modify_hot_folder_command->store($nested_job_chain,"./test/nested"))  { echo 'error occurred adding job_chain: ' . $modify_hot_folder_command->get_error(); exit; }

    ...

     

    ...


    Generated XML

    Code Block
    <modify_hot_folder folder="./test/chains">
    <order  at="now+60" id="my_Order" job_chain="myJob_Chain" priority="10" replace="yes" state="1" title="Testorder">
    <params>
    <param name="test" value="any value"/>
    </params>
    </order>
    </modify_hot_folder>


    <modify_hot_folder folder="./test/chains">
    <order  at="now+60" id="my_Order" job_chain="myJob_Chain" priority="10" replace="yes" state="1" title="Testorder">
    <params>
    <param name="test" value="any value"/>
    </params>
    </order>
    </modify_hot_folder>
    
      

     

    ...

     

    Adding a nested job chain to a hot folder

    Code Block
    languagephp
    linenumberstrue
    //-------------------------------------------------------------
    // How to add an order to a hot_folder
    //-------------------------------------------------------------
    $order_launcher = &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
    //Create an order object (SOS_Scheduler_Command_Order).
    $order = $order_launcher->order('myJob_Chain',1);
    //Setting some properties of the order object
    $order->id='my_Order';
    $order->replace="yes";
    $order->priority="10"; 
    $order->title="Testorder"; 
    $order->web_service=""; 
    $order->at="now+60";
    $order->addParam('test','any value');
    //Adding the job_chain to the hotfolder
    $modify_hot_folder_command = 

     

    ...

     <modify_hot_folder>
     <job_chain name="myNestedJob_Chain">
    
       <job_chain_node.job_chain
          job_chain="myJob_Chain"
          state="100" next_state="200"
          error_state="1200"/>
    
       <job_chain_node.job_chain
          job_chain="myNext_Chain"
          state="200"
          next_state="300"
          error_state="1200"/>
    
       <job_chain_node.end
          state="1200"/>
       <job_chain_node.end
          state="300"/>
    
    </job_chain>
    </modify_hot_folder>
    
    
      

     

    PHP XML Interface

    ...

    ...

    • Unzip package_scheduler.zip to folder package in your web folder .
    • Unzip package_class.zip to folder package in your web folder

    ...

    JobScheduler – Program Interface

    This document describes how applications can communicate with the JobScheduler. Possible tasks could be as follows:

    • Temporary creation of jobs
    • Starting jobs
    • Adding jobs
    • Changing runtime
    • Etc.

    The communication is explained by the means of PHP examples. However you can use any other programming language of your choice.

    Communication

    The communication with JobScheduler takes place via TCP, where XML commands are transmitted. You can check the documentation for the possible XML commands: http://www.sos-berlin.com/doc/en/scheduler.doc/index.xml

    Note: All changes, which are made using the xml-commands vie TCP-communication are not persistent. E.g. added jobs are no longer available after restarting the JobScheduler

    Example:

    ...

                <add_jobs>
                  <job name="myJob"
                       title = "my first job">
                    <script language="shell">
                    <![CDATA[
                        dir c:\temp
                    ]]>
                    </script>
                    <run_time>
                       <period single_start="18:00"/>
                    </run_time>
                  </job>
               </add_jobs>
              

    Example with Telnet

    ...

    The following XML string can be send e.g. via Telnet

    (The JobScheduler receives commands)

            <add_jobs>
              <job name="myJob" title = "my first job">
                <script language="shell">
                <![CDATA[dir c:\temp  ]]>
                </script>  <run_time>
                <period single_start="18:00"/>
                </run_time>
              </job>
            </add_jobs>

    (The JobScheduler answers)

            <?xml version="1.0" encoding="ISO-8859-1"?>
            <spooler>
              <answer time="2008-04-08 15:50:33.536">
                <ok/>
             </answer>
            </spooler>
          

    Example with PHP Socket Communication (@fsockopen)

    1.       //open Socket
    2.       $socket = fsockopen("localhost", "4454", $errno,$errstr, 60);
    3.  
    4.       //build command
    5.       $cmd = '<add_jobs><job name="myJob" title = "my first job"> <script';
    6.       $cmd += 'language="shell">  <![CDATA[dir c:\temp  ]]>  </script> ';     
    7.       $cmd += '<run_time> <period ';     
    8.       $cdm += 'single_start="18:00"/></run_time></job></add_jobs>';
    9.  
    10.       //send command
    11.       fputs( $socket, $cmd );
    12.  
    13.       //Socket schließen
    14.       fclose( $socket);

    After the JobScheduler has answered, you can view the Job in the Web GUI of the JobScheduler.

    ...

    Evaluate Answer

    The following function delivers the JobSchedulers answers in one string. The JobScheduler delivers the answer via the same socket, that was previously used during fputs, e.g. the answer can also be delivered directly after fputs.

    1.       function get_answer($socket) {
    2.        $answer = ''; $s = '';
    3.        while ( !ereg("</spooler>", $s) && !ereg("<ok[/]?>", $s) ) {
    4.          $s = fgets($socket, 1000);
    5.          
    6.          if (strlen($s) == 0) { break; }
    7.          $answer .= $s;
    8.          $s = substr($answer, strlen($answer)-20);
    9.  
    10.          // chr(0) am Ende entfernen.
    11.          if (substr($answer, -1) == chr(0)) {
    12.            $answer = substr($answer, 0, -1);
    13.            break;
    14.          }
    15.        }
    16.        $answer = trim($answer);
    17.  
    18.        return $answer;
    19.      }

    Communication with PHP Classes

    For an application that sends commands to the JobScheduler it is very usefull to have a proper error handling. Apart from that, a higher level of abstraction is useful for understanding the source code. For this reason SOS GmbH offers a class for processing the communication. The class encapsulates the socket calls and provides a method for reading XML answers of the JobScheduler.

    ...

    In your web directory set up a file called: packages.

    Into the folder scheduler put the file sos_scheduler_command_inc.php and into the folder class put the file sos_class.inc.php. You can find these files unter scheduler/php_xml_interface/packages.zip

    In your application program include the class with:

    ...

    The example can be realized with these classes as follows:

    1.      //open socket
    2.      $command = new SOS_Scheduler_Command(‘localhost’,4454, 60);
    3.  
    4.      //build command
    5.      $cmd = '<add_jobs><job name="myJob" title = "my first job"> <script';
    6.      $cmd += 'language="shell">  <![CDATA[dir c:\temp  ]]>  </script> ';
    7.      $cmd += '<run_time> <period ';
    8.      $cdm += 'single_start="18:00"/></run_time></job></add_jobs>';
    9.  
    10.      if (!$command->connect()) {
    11.         echo $get_error(). __FILE__ . __LINE__ ;
    12.         return 0;
    13.      }
    14.    
    15.      //send command
    16.      $this->command->command($cmd);
    17.  
    18.      if ($command->get_answer_error()) {
    19.         echo  $command->get_error() . ‘ ‘ . __FILE__ . ‘ ‘ . __LINE__ ;
    20.      }
    21.  
    22.      //close socket
    23.      $command->disconnect();
    24.  

    Commands with xml-php Interface

    One of the key tasks for the communication with JobScheduler is the creation of XML commands. To this end, you could use string functions or DOM classes

    Another possibility is to use the xml-php-interface. The interface encapsulates the construction of XML commands and the communication with the JobScheduler. In this case the classes described in Communication with PHP Classes are used.

    The advantage when using these classes is the easy handling when assembling the XML data stream.

    Within your application you have to setup the Include directory.

    ...

    The example with these classes is realized as follows:

    1. if(!defined('APP_SCHEDULER_HOST')) { define ( 'APP_SCHEDULER_HOST', 'localhost' ); }
    2. if(!defined('APP_SCHEDULER_PORT')) { define ( 'APP_SCHEDULER_PORT', '4454' ); }
    3.  
    4. //load missing classes and returns an object of the class
    5. function &get_instance($class, $include_path='scheduler/', $extension='.inc.php') {
    6.  if ( !class_exists($class) ) {
    7.    include( $include_path . strtolower($class) . $extension );
    8.  }
    9.  $object = new $class;
    10.  $object->host=APP_SCHEDULER_HOST;
    11.  $object->port=APP_SCHEDULER_PORT;
    12.  
    13.   return $object;   
    14. }
    15.  
    16. $job = &get_instance('SOS_Scheduler_Job','scheduler/');
    17.  
    18. //Setting some properties
    19. $job->name           = "myJob";
    20. $job->title          = "my first job ";
    21.  
    22. //Set the implentation
    23. $job->script('shell')->script_source='dir c:\temp';
    24.  
    25. //The job has a runtime
    26. $job->run_time()->period()->single_start = "18:00";
    27.  
    28. $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
    29.  
    30.  
    31. if (! $job_command->add_jobs($job))  {
    32. echo 'error occurred adding job: ' . $job_command->get_error(); exit; } 

    Example of Use

    For the following examples it is assumed that this code is preceeding.

    1. if(!defined('APP_SCHEDULER_HOST')) { define ( 'APP_SCHEDULER_HOST', 'localhost' ); }
    2. if(!defined('APP_SCHEDULER_PORT')) { define ( 'APP_SCHEDULER_PORT', '4454' ); }
    3.  
    4. //load missing classes and returns an object of the class
    5. function &get_instance($class, $include_path='scheduler/', $extension='.inc.php') {
    6.    if ( !class_exists($class) ) {
    7.      include( $include_path . strtolower($class) . $extension );
    8.    }
    9.    $object = new $class;
    10.    $object->host=APP_SCHEDULER_HOST;
    11.    $object->port=APP_SCHEDULER_PORT;
    12.  
    13.    return $object;   
    14. } 

    The use of the php-xml interface is explained. You can find a detailed documentation of the classes in the formats PHP and DOC under: http://www….

    At the end of each example you can see the XML code that will be send to JobScheduler.

    Adding a Order to a Job Chain

    1. //------------------------------------------------------------------------- 
    2. // How to add an order to an existing jobchain
    3. //-------------------------------------------------------------------------   
    4.  
    5. $order_launcher =
    6.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
    7.  
    8.  
    9. //Create an add_order object (SOS_Scheduler_Command_Add_Order).
    10.   $order = $order_launcher->add_order('jobchain',1);
    11.  
    12.  
    13. //Setting some properties of the order object
    14.   $order->id='sostest_12';
    15.   $order->replace="yes";
    16.   $order->priority="10"
    17.   $order->title="Testorder"
    18.   $order->web_service=""
    19.   $order->at="now+60";
    20.   $order->addParam('test','any value');
    21.  
    22. // Sending XML to the JobScheduler
    23.   if (!$order_launcher->execute($order)) {
    24.     echo 'error occurred adding order: '$order_launcher->get_error(); exit;
    25.  

    ...

        <add_order
            at="now+60"
            id="sostest_12"
            job_chain="jobchain"
            priority="10"
            replace="yes"
            state="1"
            title="Testorder">
        <params>
        <param name="test" value="any value"/>
        </params>
        </add_order>
      

    Remove an Order from a Job Chain

    1. //------------------------------------------------------------------------- 
    2. // How to add an order to an existing jobchain
    3. //-------------------------------------------------------------------------   
    4.  
    5. $order_launcher =
    6.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
    7.  
    8.  
    9. //Create an add_order object (SOS_Scheduler_Command_Add_Order).
    10.   $order = $order_launcher->add_order('jobchain',1);
    11.  
    12.  
    13. //Setting some properties of the order object
    14.   $order->id='sostest_12';
    15.   $order->replace="yes";
    16.   $order->priority="10"
    17.   $order->title="Testorder"
    18.   $order->web_service=""
    19.   $order->at="now+60";
    20.   $order->addParam('test','any value');
    21.  
    22. // Sending XML to the JobScheduler
    23.   if (!$order_launcher->execute($order)) {
    24.     echo 'error occurred adding order: '$order_launcher->get_error(); exit;
    25.   }
    26.  

    ...

        <remove_order  order="sostest_13" job_chain="jobchain"/>
    

    Change an Existing Order

    1. //------------------------------------------------------------------------
    2. //How to change an existing order
    3. //------------------------------------------------------------------------ 
    4.  
    5. //starting with adding an order.
    6. $order_launcher =
    7.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
    8.  
    9. $order = $order_launcher->add_order('jobchain',3);
    10. $order->replace='yes';
    11. $order->id='sostest_14';
    12. $order->run_time()->single_start="22:00";
    13.  
    14. if (!$order_launcher->execute($order)) {
    15.    echo 'error occurred adding order: ' . $order_launcher->get_error(); exit;
    16. }
    17.  
    18. //Now change the order.state
    19.  $order = $order_launcher->modify_order('jobchain','sostest_14');
    20.  $order->state=2;
    21.  if (!$order_launcher->execute($order)) {
    22.     echo 'error occurred modifying order: ' . $order_launcher->get_error(); exit;
    23.  } 

    ...

    <modify_order  order="sostest_14" job_chain="jobchain" state="2"></modify_order>

    Start an Order with Submit

    1. //-----------------------------------------------------------------------
    2. // How to start an order with submit.
    3. // This can be usefull, when you know orders jobchain, id, state and starttime.
    4. //------------------------------------------------------------------------
    5.  
    6. $order_launcher =
    7.        &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
    8.  
    9. if (! $order_launcher->submit('jobchain','sostest_15',2,'now+30')) {
    10.   echo 'error occurred submitting order: ' . $order_launcher->get_error(); exit;
    11. }
    12.  

    ...

        <add_order
          at="now+30"
          id="sostest_15"
          job_chain="jobchain"
          replace="yes"
          state="2">
        </add_order>
      

    Adding a Job

    1. //------------------------------------------------------------------------
    2. // How to add a job
    3. //------------------------------------------------------------------------
    4.  
    5. $job = &get_instance('SOS_Scheduler_Job','scheduler/');
    6.  
    7.  
    8. //Setting some properties
    9. $job->force_idle_timeout   = "yes";
    10. $job->idle_timeout         = "1000";
    11. $job->ignore_signals       = "all";
    12. $job->java_options         = "java";
    13. $job->min_tasks            = "2";
    14. $job->name                 = "test_jobname3"
    15. $job->order                = "no";
    16. $job->priority             = "1" ;
    17. $job->stop_on_error        = "no";
    18. $job->tasks                = "4";
    19. $job->temporary            = "no"
    20. $job->timeout              = "10";
    21. $job->title                = "my job";
    22. $job->visible              = "yes"
    23.  
    24.  
    25.  
    26. //Defining some parameters
    27. $job->addParam('var1','value1');
    28. $job->addParam('var2','value2');
    29.  
    30.  
    31. //Set the implentation
    32. $job->script('javascript')->script_source='a=1;';
    33.  
    34.  
    35. //The job has a runtime
    36.  $job->run_time()->period()->single_start = "10:00";
    37.  $job->run_time()->period()->single_start = "11:00";
    38.  
    39.  $job->run_time()->at('2006-12-24 12:20');
    40.  $job->run_time()->at('2006-12-24 12:25');
    41.  $job->run_time()->at('2006-12-24 12:35');
    42.  
    43.  
    44.  /** A period forr day=1 */
    45.  $p = $job->run_time()->weekdays('1')->period();
    46.  $p->single_start = '07:30';
    47.  
    48.  $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
    49.  
    50.  
    51.  //First removing the job   
    52.  $job_command->remove($job->name);
    53.  if (! $job_command->add_jobs($job))  {
    54.   echo 'error occurred adding job: ' . $job_command->get_error(); exit;
    55.  

    ...

        <job
          force_idle_timeout="yes"
          idle_timeout="1000"
          ignore_signals="all"
          java_options="java"
          min_tasks="2"
          name="test_jobname3"
          order="no"
          priority="1"
          stop_on_error="no"
          tasks="4"
          temporary="no"
          imeout="10"
          itle="my job"
          isible="yes">
        <params>
          param name="var1" value="value1"/>
          param name="var2" value="value2"/>
        </params>
        <script language="javascript">
          ![CDATA[a=1;]]></script>
        <run_time>
          period single_start="10:00"/>
          period single_start="11:00"/>
          at at="2006-12-24 12:20"/>
          at at="2006-12-24 12:25"/>
          at at="2006-12-24 12:35"/>
          weekdays>
            day day="1">
            period single_start="07:30"/>
            day>
          </weekdays>
        </run_time>
        </job>
      

    Deleting a Job

    1. //------------------------------------------------------------------------       
    2. // How to to delete a job
    3. //------------------------------------------------------------------------ 
    4.  
    5. // First we add the job to have one, which we can remove
    6.   $job = &get_instance('SOS_Scheduler_Job','scheduler/');
    7.  
    8.   $job->name         = "jobtoberemoved";
    9.   $job->title        = "my removed job";
    10.   $job->visible      = "yes"
    11.  
    12.  
    13. //Set the implentation
    14.   $job->script('javascript')->script_source='a=1;';
    15.  
    16.   $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
    17.  
    18.   if (! $job_command->add_jobs($job)) {
    19.     echo 'error occurred adding job: ' . $job_command->get_error(); exit;
    20. }
    21.  
    22.  
    23. //Now the job will be removed
    24.   if (! $job_command->remove($job->name)) {
    25.      echo 'error occurred removing job: ' . $job_command->get_error(); exit;
    26.   } 

    ...

        <job name="jobtoberemoved" tasks="1" temporary="no"
        title="my removed
        job" visible="yes">
        <script language="javascript">
        <![CDATA[a=1;]]>
        </script>
        </job>
    
        <modify_job job="jobtoberemoved" cmd="remove"/>
      

    Starting a Job

    1. //------------------------------------------------------------------------
    2. //  How to Start a job
    3. //------------------------------------------------------------------------
    4.  
    5.  
    6. // First we add the job to have one, which we can start
    7.  
    8.  $job = &get_instance('SOS_Scheduler_Job','scheduler/');
    9.  $job->name             = "test_jobname3"
    10.  $job->title            = "my job";
    11.  $job->visible          = "yes"
    12.  
    13.  $job->script('javascript')->script_source='a=1';
    14.  
    15.  $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
    16.  
    17.  if (! $job_command->add_jobs($job))  {
    18.    echo 'error occurred adding job: ' . $job_command->get_error(); exit;
    19.   }
    20.  
    21.  if (! $job_command->start($name='test_jobname3', $start_at="now" )) {
    22.    echo 'error occurred submitting job: ' . $job_command->get_error(); exit;
    23.         }

    ...

         start_job job="test_jobname3" at="now"></start_job>
     

    Setting the runtime of a job

    1.   //-------------------------------------------------------------------
    2.   //  How to set the runtime of a job. Some examples
    3.   //-------------------------------------------------------------------
    4.   // First we add the job to have one, which we can start
    5.  
    6.   $job = &get_instance('SOS_Scheduler_Job','scheduler/');
    7.   $job->name                  = "test_jobname33"
    8.   $job->title                 = "test_jobname33";
    9.   $job->visible                 = "yes";   
    10.    
    11.   $job->script('javascript')->script_source='a=1';
    12.  
    13.   $job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');
    14.  
    15.   if (! $job_command->add_jobs($job))  { echo 'error occurred adding job: ' . $job_command->get_error(); exit; }
    16.  
    17.   //Start on the 28.st at 11:00
    18.   $job->run_time()->monthdays('28')->period()->single_start='11:00';
    19.  
    20.   //Adding a period
    21.   $period = new SOS_Scheduler_Runtime_Period();
    22.   $period->begin='12:00'; $period->end='13:00';
    23.   $period->repeat='60';
    24.   $job->run_time()->date('2006-30-11')->addPeriod($period);
    25.  
    26.   //starting at 11:00
    27.   $job->run_time()->at('11:00');
    28.   if (!$job_command->execute($job)) { echo 'error occurred : ' . $job_command->get_error(); exit; } 

    ...

    <job name="test_jobname33"
         tasks="1"
         title="test_jobname33"
         visible="yes">
    <script language="javascript"><![CDATA[a=1]]></script>
    
    <run_time>
    <at at="11:00"/>
    <date date="2006-30-11">
    <period begin="12:00"
            end="13:00"
            repeat="60"/>
    </date>
    <monthdays>
           <day day="28">
              <period single_start="11:00"/>
           </day>
    </monthdays>
    </run_time>
    </job>
    
     

    Setting the runtime of an order

    1. //--------------------------------------------------------------
    2. //How to set the runtime of an order. Some examples
    3. //--------------------------------------------------------------
    4.  
    5. //adding an order with a runtime
    6.  
    7. $order_launcher = &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
    8. $order = $order_launcher->add_order('jobchain',3);
    9. $order->replace='yes';
    10. $order->id='sostest_14';
    11.  
    12. //Start on the 28.st at 11:00
    13. $order->run_time()->monthdays('28')->period()->single_start='12:00';
    14.  
    15. //Adding a period
    16. $period = new SOS_Scheduler_Runtime_Period();
    17. $period->begin='12:00'; $period->end='13:00';
    18. $period->repeat='60';
    19. $order->run_time()->ultimos('22')->addPeriod($period);
    20.  
    21. //starting at 11:00
    22. $order->at='2008-11-01 13:00';
    23.  
    24.  
    25. if (!$order_launcher->execute($order)) { echo 'error occurred adding order: ' . $order_launcher->get_error(); exit; } 

    ...

     <add_order
      at="2008-11-01 13:00"
      id="sostest_14"
      job_chain="jobchain"
      replace="yes"
      state="3">
    <run_time>
       <monthdays>
         <day day="28">
           <period single_start="12:00"/>
        </day></monthdays>
        <ultimos>
          <day day="22">
           <period begin="12:00" end="13:00" repeat="60"/>
          </day>
        </ultimos>
    </run_time>
    </add_order>
    
    
    
    

    Working with hot folders

    Adding a Job to a hot folder

    1. // First we add the job to have one, which we can start
    2.  
    3.   $job = &get_instance('SOS_Scheduler_Job','scheduler/');
    4.   $job->name                  = "test_jobname77"
    5.   $job->title                 = "test_jobname77";
    6.   $job->visible                 = "yes";   
    7.    
    8.   $job->script('javascript')->script_source='a=1';
    9.  
    10.   $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');
    11.  
    12.   if (! $xml=$modify_hot_folder_command->store($job,"./test"))  { echo 'error occurred adding job: ' . $modify_hot_folder_command->get_error(); exit; }
    13.  

    ...

     <modify_hot_folder folder="./test">
       <job name="test_jobname77" tasks="1" temporary="no" title="test_jobname77" visible="yes">
         <script language="javascript"><![CDATA[a=1]]></script>
       </job>
    </modify_hot_folder>
      

    Adding a Lock to a hot folder

    1. //--------------------------------------------------
    2.   //  How to add a lock to hot folder
    3.   //--------------------------------------------------
    4.   // First we add the lock to have one, which we can start
    5.   $lock = &get_instance('SOS_Scheduler_Lock','scheduler/');
    6.  
    7.   //Setting some properties
    8.   $lock->max_non_exclusive           = 1;
    9.   $lock->name="myLock";
    10.  
    11.    //Adding the lock to the hotfolder
    12.     $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');
    13.     if (! $xml=$modify_hot_folder_command->store($lock,"./test"))  { echo 'error occurred adding lock: ' . $modify_hot_folder_command->get_error(); exit; }
    14.  
    15.  

    ...

    <modify_hot_folder folder="./test">
      <lock name="myLock" max_non_exclusive="1"></lock>
    </modify_hot_folder><br>
     

    Adding a Process_class to a hot folder

    1. //-------------------------------------------------------------------------
    2.   //  How to add a process_class to hot folder
    3.   //-------------------------------------------------------------------------
    4.   // First we add the process_class to have one, which we can start
    5.   $process_class = &get_instance('SOS_Scheduler_Process_class','scheduler/');
    6.  
    7.   //Setting some properties
    8.   $process_class->max_processes           = 1;
    9.   $process_class->name=

    ...

    <modify_hot_folder folder="./test">
       <process_class
          name="myProcess_class"
          max_processes="1" replace="yes">
       </process_class>
     </modify_hot_folder>
      

    Adding a Job_Chain to a hot folder

    1. //-------------------------------------------------------------
    2.   //  How to add a job_chain to hot folder
    3.   //-------------------------------------------------------------
    4.      $job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/');
    5.  
    6.    //Setting some properties
    7.      $job_chain->name           = "myJob_Chain";
    8.  
    9.  
    10.     //The job has a file_order_sources
    11.      $job_chain->file_order_source("/myDir","1");
    12.      $job_chain->file_order_source("/myOtherDir","2");
    13.  
    14.     //The job has a file_order_sinks
    15.      $job_chain->file_order_sink("6")  ->remove="yes";
    16.      $job_chain->file_order_sink("99") ->remove="yes";
    17.      $job_chain->file_order_sink("999")->remove="yes";
    18.  
    19.     //Adding some Job_chain_nodes
    20.      $job_chain->add_job("my_job1","1","2","99");
    21.      $job_chain->add_job("my_job2","2","3","99");
    22.      $job_chain->add_job("my_job3","3","4","99");
    23.      $job_chain->add_job("my_job4","4","5","999");
    24.      
    25.      //or adding a node
    26.      $job_chain_node = new SOS_Scheduler_Job_Chain_Node();
    27.  
    28.    //Setting some properties
    29.       $job_chain_node->state          = "5";  
    30.       $job_chain_node->error_state      = "99";    
    31.       $job_chain_node->next_state     = "6";    
    32.       $job_chain_node->on_error       = "suspend";
    33.       $job_chain_node->job              = "myJob5";
    34.    
    35.    //adding the node
    36.       $job_chain->add_node($job_chain_node);
    37.  
    38.  //Adding the job_chain to the hotfolder
    39.     $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');
    40.    if (! $xml=$modify_hot_folder_command->store($job_chain,"./test/chains"))  { echo 'error occurred adding job chain: ' . $modify_hot_folder_command->get_error(); exit; }
    41.  

    ...

    <modify_hot_folder folder="./test/chains">
      <job_chain name="myJob_Chain">
        <file_order_source directory="/myDir"/>
        <file_order_source directory="/myOtherDir"/>
        <file_order_sink state="6" remove="yes"/>
        <file_order_sink state="99" remove="yes"/>
        <file_order_sink state="999" remove="yes"/>
        <job_chain_node job="my_job1" state="1" next_state="2" error_state="99"/>
        <job_chain_node job="my_job2" state="2" next_state="3" error_state="99"/>
        <job_chain_node job="my_job3" state="3" next_state="4" error_state="99"/>
        <job_chain_node job="my_job4" state="4" next_state="5" error_state="999"/>
        <job_chain_node job="myJob5" state="5" next_state="6" error_state="99"/>
        </job_chain>
    </modify_hot_folder>
    
      

    Adding an Order to a hot folder

    1. //-------------------------------------------------------------
    2.   // How to add an order to a hot_folder
    3.   //-------------------------------------------------------------
    4.  
    5.   $order_launcher = &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
    6.  
    7.   //Create an order object (SOS_Scheduler_Command_Order).
    8.   $order = $order_launcher->order('myJob_Chain',1);
    9.  
    10.   //Setting some properties of the order object
    11.   $order->id='my_Order';
    12.   $order->replace="yes";
    13.   $order->priority="10"
    14.   $order->title="Testorder"
    15.   $order->web_service=""
    16.   $order->at="now+60";
    17.   $order->addParam('test','any value');
    18.  
    19.   //Adding the job_chain to the hotfolder
    20.    $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');
    21.    if (! $xml=$modify_hot_folder_command->store($order,"./test/chains"))  { echo 'error occurred adding order: ' . $modify_hot_folder_command->get_error(); exit; } 

    ...

    <modify_hot_folder folder="./test/chains">
    <order  at="now+60" id="my_Order" job_chain="myJob_Chain" priority="10" replace="yes" state="1" title="Testorder">
    <params>
    <param name="test" value="any value"/>
    </params>
    </order>
    </modify_hot_folder>
    
      

    Adding a nested job chain to a hot folder

    ...

      //-------------------------------------------------------------

    ...

      // How to add a job_chain to a job_chain

    ...

      //-------------------------------------------------------------

    ...

     

    ...

     

    ...

        $job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/');

    ...

     

    ...

       // First setting up two job_chains.

    ...

     

    ...

       //First job_chain

    ...

         $job_chain->name           = "myJob_Chain";

    ...

     

    ...

        //Adding some Job_chain_nodes

    ...

         $job_chain->add_job("my_job1","1","50","99");

    ...

         $job_chain->add_job("my_job2","2","50","99");

    ...

     

    ...

        //Adding the endnodes

    ...

         $job_chain->add_end_node("99");

    ...

         $job_chain->add_end_node("50");

    ...

     

    ...

     //Adding the job_chain to the hotfolder

    ...

        $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');

    ...

       if (! $xml=$modify_hot_folder_command->store($job_chain,"./test/nested"))  { echo 'error occurred adding job_chain: ' . $modify_hot_folder_command->get_error(); exit; }

    ...

     

    ...

     

    ...

       //Second job_chain

    ...

        $next_job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/');

    ...

        $next_job_chain->name           = "myNext_Chain";

    ...

     

    ...

     

    ...

        //Adding some Job_chain_nodes

    ...

         $next_job_chain->add_job("my_job3","1","50","99");

    ...

         $next_job_chain->add_job("my_job4","2","50","99");

    ...

         

    ...

        //Adding the endnodes

    ...

         $next_job_chain->add_end_node("99");

    ...

         $next_job_chain->add_end_node("50");

    ...

       

    ...

     //Adding the job_chain to the hotfolder

    ...

        $modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');

    ...

       if (! $xml=$modify_hot_folder_command->store($next_job_chain,"./test/nested"))  { echo 'error occurred adding job_chain: ' . $modify_hot_folder_command->get_error(); exit; }

    ...

     

    ...

     //Now creating a third job_chain which contains the first and the second.

    ...

        $nested_job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/');

    ...

        $nested_job_chain->name = "myNestedJob_Chain";

    ...

     

    ...

     //Adding the first nested job_chain.

    ...

        $job_chain_node = new SOS_Scheduler_Job_Chain_Node_Job_Chain("100");

    ...

     

    ...

       //Setting some properties

    ...

          $job_chain_node->state          = "100";    

    ...

          $job_chain_node->next_state       = "200";    

    ...

          $job_chain_node->error_state      = "1200";  

    ...

          $job_chain_node->job_chain      = "myJob_Chain";

    ...

        //Adding the job_chain_node to the job_chain;

    ...

          $nested_job_chain->add_node($job_chain_node);

    ...

     

    ...

        //Adding a second job_chain with -> add_job_chain();

    ...

        $nested_job_chain->add_job_chain("myNext_Chain","200","300","1200");

    ...

     

    ...

        //Adding the endnodes

    ...

          $nested_job_chain->add_end_node("1200");

    ...

          $nested_job_chain->add_end_node("300");

    ...

     

    ...

     

    ...

        //Adding the job_chain  to the hotfolder

    ...

    &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/');

    ...

    
    if (! $xml=$modify_hot_folder_command-

    ...

    >store($order,"./test/

    ...

    chains"))

    ...

      {echo'error occurred adding

    ...

     order: ' . $modify_hot_folder_command-

    ...

    >get_error(); exit; }
    
    

     

    ...


    Generated XML

    ...

    Code Block
    languagexml
     <modify_hot_folder>
     <job_chain name="myNestedJob_Chain">
    
       <job_chain_node.job_chain
          job_chain="myJob_Chain"
          state="100" next_state="200"
          error_state="1200"/>
    
       <job_chain_node.job_chain
          job_chain="myNext_Chain"
          state="200"
          next_state="300"
          error_state="1200"/>
    
       <job_chain_node.end
          state="1200"/>
       <job_chain_node.end
          state="300"/>
    
    </job_chain>
    </modify_hot_folder>

    ...