Job Queue Functions

A Queue of Job is described using the JobQueue class, when you want to manage a queue (or add more than one job to it) you should instantiate a JobQueue object.

The JobQueue object enables several job control functions such as: add/remove/suspend/resume, and some manage/info queue functions like: getJobsInQueue, getHistory, getStatistics etc.

A job is described by a Job class, whenever you want to add/update a job you can handle the Job object using the Job methods.

After a job is in the queue, you can retrieve it to change remove or suspend the Job by using the job id (the job id is assigned when a Job is added to the queue or by querying the jobs in the queue)

To add one job to a queue, for simplicity of usage, you can create the Job object (with it's required attributes) and then add the job directly from the Job object (without instantiating the JobQueue object), using the Job::addJob() function.

To change a Job's attributes, first get it from the queue (JobQueue::getJob() function), change the attributes and then update the queue with the changed Job object (JobQueue::updateJob() functions).

Global Functions and Constants

Constants for Job statuses

define('JOB_QUEUE_STATUS_SUCCESS', 1);  

Job was processed and succeeded

define('JOB_QUEUE_STATUS_WAITING', 2);         

 

Job is waiting to be processed (was not scheduled)

define('JOB_QUEUE_STATUS_SUSPENDED', 3);  

Job was suspended

define('JOB_QUEUE_STATUS_SCHEDULED', 4);  

Job is scheduled and waiting in queue

define('JOB_QUEUE_STATUS_WAITING_PREDECESSOR', 5);

Job is waiting for it's predecessor to be completed

define('JOB_QUEUE_STATUS_IN_PROCESS', 6);    

Job is in process in Queue

define('JOB_QUEUE_STATUS_EXECUTION_FAILED', 7);    

Job execution failed in the ZendEnabler

define('JOB_QUEUE_STATUS_LOGICALLY_FAILED', 8);

Job was processed and failed logically either because of job_fail command or script parse or fatal error

Constants for different priorities of jobs

define('JOB_QUEUE_PRIORITY_LOW', 0);

define('JOB_QUEUE_PRIORITY_NORMAL', 1);

define('JOB_QUEUE_PRIORITY_HIGH', 2);

define('JOB_QUEUE_PRIORITY_URGENT', 3);

Constants for saving global variable's bit mask

define('JOB_QUEUE_SAVE_POST', 1);

define('JOB_QUEUE_SAVE_GET', 2);

define('JOB_QUEUE_SAVE_COOKIE', 4);

define('JOB_QUEUE_SAVE_SESSION', 8);

define('JOB_QUEUE_SAVE_RAW_POST', 16);

define('JOB_QUEUE_SAVE_SERVER', 32);

define('JOB_QUEUE_SAVE_FILES', 64);

define('JOB_QUEUE_SAVE_ENV', 128);

set_job_failed

set_job_failed( $error_string );

jobqueue_license_info

jobqueue_license_info();

Queue Class

class ZendAPI_Queue {

var $_jobqueue_url;

Queue Class Functions

zendapi_queue($queue_url) {}

Constructor for a job queue connection

login($password, $application_id=null) {}

Opens a connection to a job queue

addJob(&$job) {}

Insert a new job to the queue, the Job is passed by reference because its new job ID and status will be set in the Job object

getJob($job_id) {}

Returns a Job object describing a job in the queue

updateJob(&$job) {}

Updates an existing job in the queue with it's new properties. If job doesn't exist, a new job will be added. Job is passed by reference and it's updated from the queue.

suspendJob($job_id) {}

Removes a job from the queue

resumeJob($job_id) {}

Resume a suspended job in the queue

requeueJob($job) {}

Re-queue failed job back to the queue.

getStatistics() {}

returns job statistics

isScriptExists($path) {}

Returns whether a script exists in the document root

isSuspend() {}

Returns whether the queue is suspended

getJobsInQueue($filter_options=null, $max_jobs=-1, $with_globals_and_output=false) {}

Returns a list of jobs in the queue according to the options given in the filter_options parameter, doesn't return jobs in "final states" (failed, complete). If the application id is set for this queue, only jobs with this application id will be returned.

getNumOfJobsInQueue($filter_options=null) {}

Returns a list of jobs in the queue according to the options given in the filter_options parameter

If application id is set for this queue, only jobs with this application id will be returned

getAllhosts() {}

Return all the hosts that jobs were submitted from @return array.

getAllApplicationIDs() {}

Return all the application ids exists in queue @return array.

getHistoricJobs($status, $start_time, $end_time, $index, $count, &$total) {}

Return finished jobs (either failed or successes) between time range allowing paging.

Jobs are sorted by job id descending.

suspendQueue() {}

Suspends queue operation

resumeQueue() {}

Resumes queue operation

getLastError() {}

Returns a description of the last error that occurred in the queue object. After every method invoked an error string describing the error is stored in the queue object.

setMaxHistoryTime() {}

Sets a new maximum time for keeping historic jobs.

Job Class

This class describes a job in a queue

In order to add/modify a job in the queue, a Job class must be created, retrieved and than saved in a queue or, a job can be added directly to a queue without creating an instant of a Queue object.

class ZendAPI_Job {

var $_id;

var $_script;

var $_host;

var $_name;

var $_output;

var $_status = JOB_QUEUE_STATUS_WAITING;

var $_application_id = null;

var $_priority = JOB_QUEUE_PRIORITY_NORMAL;

var $_user_variables = array();

var $_global_variables = 0;

var $_predecessor = null;

var $_scheduled_time = 0;

var $_interval = 0;

var $_end_time = null;

var $_preserved = 0;

function ZendAPI_Job($script) {}

function addJobToQueue($jobqueue_url, $password) {}

function setJobPriority($priority) {}

All properties SET functions

function setJobName($name) {}

function setScript($script) {}

function setApplicationID($app_id) {}

function setUserVariables($vars) {}

function setGlobalVariables($vars) {}

function setJobDependency($job_id) {}

function setScheduledTime($timestamp) {}

function setRecurrenceData($interval, $end_time=null) {}

function setPreserved($preserved)

function getProperties() {}

function getOutput() {}

All properties GET functions

function getID() {}

function getHost() {}

function getScript() {}

function getJobPriority() {}

function getJobName() {}

function getApplicationID() {}

function getUserVariables() {}

function getGlobalVariables() {}

function getJobDependency() {}

function getScheduledTime() {}

function getInterval() {}

function getEndTime() {}

function getPreserved() {}

function getJobStatus() {}

function getTimeToNextRepeat() {}

function getLastPerformedStatus() {}

 

 

Related Links

Related Links:
Job Queues

Job Queue API