Versions Compared

Key

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

...

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 JobScheduler's web interface, JOC.

...

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->host=APP_SCHEDULER_HOST;
	$object->port=APP_SCHEDULER_PORT;
	return $object;   
} 

...

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

...

Remove an Order from a Job Chain

Code Block
languagephp
firstline15
linenumberstrue
 

 

...

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

...

  
// How to add an order to an existing jobchain

...


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

...

 
    

$order_launcher

...

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

...

 

...

 


//Create an add_order object (SOS_Scheduler_Command_Add_Order).

...


$order = $order_launcher-

...

>add_order('jobchain',1);

...

 

...

 


//Setting some properties of the order object

...


$order-

...

>id='sostest_12';

...


$order-

...

>replace="yes";

...


$order-

...

>priority="10";

...

 
$order-

...

>title="Testorder";

...

 
$order-

...

>web_service="";

...

 
$order-

...

>at="now+60";

...


$order-

...

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

...

 


// Sending XML to the JobScheduler

...


if (!$order_launcher-

...

>execute($order)) {

...


	echo'error occurred adding order: ' .

...

  $order_launcher-

...

>get_error();
	exit;

...


}

...

 

 

...


Generated XML

Code Block
 

...

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

...

 

...

Change an Existing Order

Code Block
languagephp
firstline15
linenumberstrue
//------------------------------------------------------------------------
//How to change an existing order
//------------------------------------------------------------------------  

//starting with adding an order.
$order_launcher =
       &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
$order = $order_launcher->add_order('jobchain',3);
$order->replace='yes';
$order->id='sostest_14';
$order->run_time()->single_start="22:00";

if (!$order_launcher->execute($order)) {
	echo'error occurred adding order: ' . $order_launcher->get_error(); exit;
}

//Now change the order.state
$order = $order_launcher->modify_order('jobchain','sostest_14');
$order->state=2;
if (!$order_launcher->execute($order)) {
	echo'error occurred modifying order: ' . $order_launcher->get_error();
	exit;
} 

...

Start an Order with Submit

Code Block
languagephp
firstline15
linenumberstrue
//-----------------------------------------------------------------------
// How to start an order with submit. 
// This can be usefull, when you know orders jobchain, id, state and starttime.
//------------------------------------------------------------------------
$order_launcher =
       &get_instance('SOS_Scheduler_OrderCommand_Launcher','scheduler/');
if (! $order_launcher->submit('jobchain','sostest_15',2,'now+30')) {
	echo'error occurred submitting order: ' . $order_launcher->get_error();
	exit;
}

...

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
firstline15
linenumberstrue
 //------------------------------------------------------------------------
// How to add a job
//------------------------------------------------------------------------

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

//Setting some properties
$job->force_idle_timeout   = "yes";
$job->idle_timeout         = "1000";
$job->ignore_signals       = "all";
$job->java_options         = "java";
$job->min_tasks            = "2";
$job->name                 = "test_jobname3"; 
$job->order                = "no";
$job->priority             = "1" ;
$job->stop_on_error        = "no";
$job->tasks                = "4";
$job->temporary            = "no"; 
$job->timeout              = "10";
$job->title                = "my job";
$job->visible              = "yes"; 

//Defining some parameters
$job->addParam('var1','value1');
$job->addParam('var2','value2');

//Set the implentation
$job->script('javascript')->script_source='a=1;';

//The job has a runtime
$job->run_time()->period()->single_start = "10:00";
$job->run_time()->period()->single_start = "11:00";
$job->run_time()->at('2006-12-24 12:20');
$job->run_time()->at('2006-12-24 12:25');
$job->run_time()->at('2006-12-24 12:35');

/** A period for day=1 */
$p = $job->run_time()->weekdays('1')->period();
$p->single_start = '07:30';
$job_command = &get_instance('SOS_Scheduler_JobCommand_Launcher','scheduler/');

//First removing the job    
$job_command->remove($job->name);
if (! $job_command->add_jobs($job))  {
	echo'error occurred adding job: ' . $job_command->get_error(); 
	exit;


} 

 

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

// How to add a job

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

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

//Setting some properties

$job->force_idle_timeout   = "yes";

$job->idle_timeout         = "1000";

$job->ignore_signals       = "all";

$job->java_options         = "java";

$job->min_tasks            = "2";

$job->name                 = "test_jobname3"

$job->order                = "no";

$job->priority             = "1" ;

$job->stop_on_error        = "no";

$job->tasks                = "4";

$job->temporary            = "no"

$job->timeout              = "10";

$job->title                = "my job";

$job->visible              = "yes"

//Defining some parameters

$job->addParam('var1','value1');

$job->addParam('var2','value2');

//Set the implentation

$job->script('javascript')->script_source='a=1;';

//The job has a runtime

$job->run_time()->period()->single_start = "10:00";

$job->run_time()->period()->single_start = "11:00";

$job->run_time()->at('2006-12-24 12:20');

$job->run_time()->at('2006-12-24 12:25');

$job->run_time()->at('2006-12-24 12:35');

/** A period forr day=1 */

$p = $job->run_time()->weekdays('1')->period();

$p->single_start = '07:30';

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

//First removing the job   

$job_command->remove($job->name);

if (! $job_command->add_jobs($job))  {

echo'error occurred adding job: ' . $job_command->get_error(); exit;

 

...

...


Generated XML

Code Block
   <job
      
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
firstline15
linenumberstrue

 

 

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

...

       
// How to to delete a job

...

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

...

 
  
// First we add the job to have one, which we can remove

...


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

...

 

...


$job->name         = "jobtoberemoved";

...

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

...

  $job->visible      = "yes"

...

 

...

 

...

//Set the implentation

...


$job->title        = "my removed job";
$job->visible      = "yes"; 
//Set the implentation
$job->script('javascript')-

...

>script_source='a=1;';

...

 

...


$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;

...

}

...

 

...

 

}
//Now the job will be removed

...


if (! $job_command-

...

>remove($job-

...

>name))

...

 {
	echo'error occurred removing job: ' . $job_command-

...

>get_error(); 
	exit;

...


}

...

 

 

...


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
firstline15
linenumberstrue

 

 

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

...


//

...

  How to Start a job

...


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

...

 

...

 


// First we add the job to have one, which we can start

...

 

...


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

...


$job->name             = "test_jobname3";

...

 $job->title            = "my job";

...

 $job->visible          = "yes"

...

 

...

 
$job->title            = "my job";
$job->visible          = "yes"; 
$job->script('javascript')-

...

>script_source='a=1';

...

 

...


$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;

...

  }

...

 

...


}

if (! $job_command-

...

>start($name='test_jobname3', $start_at="now" )) {

...


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

...

>get_error();
	exit;

...


}

 

...


Generated XML

Code Block
 

...

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

...

    

...

...

 

Setting the runtime of a job

Code Block
languagephp
firstline15
linenumberstrue
 

 

 

...

//-------------------------------------------------------------------
//  How to set the runtime of a job. Some examples
//-------------------------------------------------------------------

...

  //  How to set the runtime of a job. Some examples

...

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

...

  // First we add the job to have one, which we can start

...

 

...

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

...

  $job->name                  = "test_jobname33"

...

  $job->title                 = "test_jobname33";

...

  $job->visible                 = "yes";   

...

   

...

  $job->script('javascript')->script_source='a=1';

...

 

...

  $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; }

...

 

...

  //Start on the 28.st at 11:00


// First we add the job to have one, which we can start
$job = &get_instance('SOS_Scheduler_Job','scheduler/');
$job->name                  = "test_jobname33"; 
$job->title                 = "test_jobname33";
$job->visible                 = "yes";   
$job->script('javascript')->script_source='a=1';
$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; }

//Start on the 28.st at 11:00
$job->run_time()->monthdays('28')->period()->single_start='11:00';

//Adding a period 
$period = new SOS_Scheduler_Runtime_Period();
$period->begin='12:00'; $period->end='13:00';
$period->repeat='60';
$job->run_time()->date('2006-30-11')->addPeriod($period);

//starting at 11:00
$job->run_time()->at('11:00');
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
firstline15
linenumberstrue

...

  $job->run_time()->monthdays('28')->period()->single_start='11:00';

...

 

...

  //Adding a period

...

  $period = new SOS_Scheduler_Runtime_Period();

...

  $period->begin='12:00'; $period->end='13:00';

...

  $period->repeat='60';

...

  $job->run_time()->date('2006-30-11')->addPeriod($period);

...

 

...

  //starting at 11:00

...

  $job->run_time()->at('11:00');

...

  if (!$job_command->execute($job)) { echo 'error occurred : ' . $job_command->get_error(); exit; } 

 

...

 
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

...

languagephp
linenumberstrue

 

 

 

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

 

 

//How to set the runtime of an order. Some examples

 

 

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

 

 

//adding an order with a runtime

 

 

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

 

 

$order = $order_launcher->add_order('jobchain',3);

 

 

$order->replace='yes';

 

 

$order->id='sostest_14';

 

 

//Start on the 28.st at 11:00

 

 

$order->run_time()->monthdays('28')->period()->single_start='12:00';

 

 

//Adding a period

 

 

$period = new SOS_Scheduler_Runtime_Period();

 

 

$period->begin='12:00'; $period->end='13:00';

 

 

$period->repeat='60';

 

 

$order->run_time()->ultimos('22')->addPeriod($period);

 

 

//starting at 11:00

 

 

$order->at='2008-11-01 13:00';

 

  •  
  • if (!$order_launcher->execute($order)) {echo'error occurred adding order: ' . $order_launcher->get_error(); exit; }

     

    br>

    ...


    Generated XML

    Code Block
     

    ...