...
Code Block | ||||
---|---|---|---|---|
| ||||
//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(); |
...
Within your application you have to setup the Include directory.
...
Code Block | ||||
---|---|---|---|---|
| ||||
ini_set( 'include_path', 'packages' ); |
...
Code Block | ||||
---|---|---|---|---|
| ||||
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; } $job = &get_instance('SOS_Scheduler_Job','scheduler/'); //Setting some properties $job->name = "myJob"; $job->title = "my first job "; //Set the implentationimplementation $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; } |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
//----------------------------------------------------------------------- // How to start an order with submit. // This can be usefulluseful, 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 | ||||||
---|---|---|---|---|---|---|
| ||||||
//------------------------------------------------------------------------ // 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 implentationimplementation $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; } |
...
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
//------------------------------------------------------------------------ // 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->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; } |
...
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> |
//--------------------------------------------------------------
//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>
...
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>
Working with hot folders
Adding a Job to a hot folder
Code Block | ||||
---|---|---|---|---|
| ||||
|
...
...
//--------------------------------------------------------------
//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; } |
...
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> |
...
Working with hot folders
...
Adding a Job to a hot folder
Code Block | ||||
---|---|---|---|---|
| ||||
// First we add the job to have one, which we can start
$job = &get_instance('SOS_Scheduler_Job','scheduler/');
$job->name = "test_jobname77";
$job->title = "test_jobname77";
$job->visible = "yes";
$job->script('javascript')->script_source='a=1';
$modify_hot_folder_command = |
...
&get_instance('SOS_Scheduler_ |
...
HotFolder_Launcher','scheduler/'); |
...
...
...
...
...
...
...
if (! $xml=$modify_hot_folder_command->store($job,"./test")) { echo'error occurred adding job: ' . $modify_hot_folder_command |
...
...
...
->get_error();
exit;
} |
...
Generated XML
...
Code Block |
---|
|
...
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 | ||||
---|---|---|---|---|
| ||||
//-------------------------------------------------- |
...
// |
...
How to add a lock to hot folder |
...
//-------------------------------------------------- |
...
// First we add the lock to have one, which we can start |
...
$lock = &get_instance('SOS_Scheduler_Lock','scheduler/'); |
...
...
//Setting some properties |
...
$lock- |
...
>max_non_exclusive |
...
= 1; $lock->name="myLock"; |
...
...
//Adding the lock to the hotfolder |
...
$modify_hot_folder_command = &get_instance('SOS_Scheduler_HotFolder_Launcher','scheduler/'); |
...
if (! $xml=$modify_hot_folder_command- |
...
>store($lock,"./test")) |
...
{ echo'error occurred adding lock: ' . $modify_hot_folder_command- |
...
>get_error(); exit; } |
...
Generated XML
Code Block |
---|
<modify_hot_folder folder="./test">
<lock name="myLock" max_non_exclusive="1"></lock>
</modify_hot_ |
...
folder> |
...
|
...
Adding a Process_class to a hot folder
Code Block | ||||
---|---|---|---|---|
| ||||
|
...
//------------------------------------------------------------------------- |
...
// |
...
How to add a process_class to hot folder |
...
//------------------------------------------------------------------------- |
...
// First we add the process_class to have one, which we can start |
...
$process_class = &get_instance('SOS_Scheduler_Process_class','scheduler/'); |
...
...
//Setting some properties |
...
$process_class- |
...
>max_processes = 1; $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 | ||||
---|---|---|---|---|
| ||||
|
//------------------------------------------------------------- |
...
// |
...
How to add a job_chain to hot folder |
...
//------------------------------------------------------------- |
...
$job_chain = &get_instance('SOS_Scheduler_Job_Chain','scheduler/'); |
...
...
//Setting some |
...
properties $job_chain->name = "myJob_Chain"; |
...
...
...
//The job has a file_order_sources |
...
$job_chain- |
...
>file_order_source("/myDir","1"); |
...
$job_chain- |
...
>file_order_source("/myOtherDir","2"); |
...
...
//The job has a file_order_sinks |
...
$job_chain- |
...
>file_order_sink("6") |
...
- |
...
>remove="yes"; |
...
$job_chain- |
...
>file_order_sink("99") - |
...
>remove="yes"; |
...
$job_chain- |
...
>file_order_sink("999")- |
...
>remove="yes"; |
...
...
//Adding some Job_chain_nodes |
...
$job_chain- |
...
>add_job("my_job1","1","2","99"); |
...
$job_chain- |
...
>add_job("my_job2","2","3","99"); |
...
$job_chain- |
...
>add_job("my_job3","3","4","99"); |
...
$job_chain- |
...
>add_job("my_job4","4","5","999"); |
...
...
//or adding a node |
...
$job_chain_node = new SOS_Scheduler_Job_Chain_Node(); |
...
...
//Setting some properties |
...
$job_chain_node- |
...
>state = "5"; |
...
$job_chain_node- |
...
>error_state |
...
= "99"; |
...
$job_chain_node- |
...
>next_state |
...
= "6"; |
...
$job_chain_node- |
...
>on_error |
...
= "suspend"; |
...
$job_chain_node- |
...
>job = "myJob5"; |
...
...
//adding the node |
...
$job_chain- |
...
>add_node($job_chain_node); |
...
...
//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/chains")) |
...
{ echo'error occurred adding job chain: ' . $modify_hot_folder_command- |
...
>get_error(); exit; } |
...
...
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 |
...
Adding an Order to a hot folder
Code Block | ||||
---|---|---|---|---|
| ||||
//-------------------------------------------------------------
// 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; }
|
// 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
...
_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 | ||||
---|---|---|---|---|
| ||||
//------------------------------------------------------------- // 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;
}
|
...
Generated XML
Code Block |
---|
if (! $xml=$modify_hot_folder_command->store($order,"./test/chains")) {echo'error occurred adding order: ' . $modify_hot_folder_command->get_error(); exit; }
...
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> |
...
...
Adding a nested job chain to a hot folder
Code Block | ||||
---|---|---|---|---|
| ||||
//------------------------------------------------------------- // 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; } |
...
Generated XML
Code Block | ||
---|---|---|
| ||
<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> |
...