Zend Job Queue

Zend Job Queue

PHP API

Class: ZendJobQueue is a PHP class that implements a connection to the Job Queue daemon
Available since: 4.0


Constant: int TYPE_HTTP
Type of HTTP job with absolute URL
Available since: 4.0


Constant: int TYPE_HTTP_RELATIVE
Type of HTTP job with relative URL
Available since: 4.0


Constant: int TYPE_SHELL
Type of SHELL job
Available since: 4.0


Constant: int PRIORITY_LOW
Low priority job
Available since: 4.0


Constant: int PRIORITY_NORMAL
Normal priority job
Available since: 4.0


Constant: int PRIORITY_HIGH
High priority job
Available since: 4.0


Constant: int PRIORITY_URGENT
Urgent priority job
Available since: 4.0


Constant: int STATUS_PENDING
Job is waiting to be processed
Available since: 4.0


Constant: int STATUS_WAITING_PREDECESSOR
Job is waiting for its predecessor's completion
Available since: 4.0


Constant: int STATUS_RUNNING
Job is executing
Available since: 4.0


Constant: int STATUS_COMPLETED
Job execution completed successfully
Available since: 4.0


Constant: int STATUS_FAILED
Job execution failed
Available since: 4.0


Constant: int STATUS_OK
Job was executed and reported its successful completion status
Available since: 4.0


Constant: int STATUS_LOGICALLY_FAILED
Job was executed but reported failed completion status
Available since: 4.0


Constant: int STATUS_TIMEOUT
Job execution timeout
Available since: 4.0


Constant: int STATUS_REMOVED
Logically removed job
Available since: 4.0


Constant: int STATUS_SCHEDULED
Job scheduled to be executed at some specific time
Available since: 4.0


Constant: int STATUS_SUSPENDED
Job execution is susspended
Available since: 4.0


Constant: int SORT_NONE
disable sortion of result set of getJobsList()
Available since: 4.0


Constant: int SORT_BY_ID
sort result set of getJobsList() by job id
Available since: 4.0


Constant: int SORT_BY_TYPE
sort result set of getJobsList() by job type
Available since: 4.0


Constant: int SORT_BY_SCRIPT
sort result set of getJobsList() by job script name
Available since: 4.0


Constant: int SORT_BY_APPLICATION
sort result set of getJobsList() by application name
Available since: 4.0


Constant: int SORT_BY_NAME
sort result set of getJobsList() by job name
Available since: 4.0


Constant: int SORT_BY_PRIORITY
sort result set of getJobsList() by job priority
Available since: 4.0


Constant: int SORT_BY_STATUS
sort result set of getJobsList() by job status
Available since: 4.0


Constant: int SORT_BY_PREDECESSOR
sort result set of getJobsList() by job predecessor
Available since: 4.0


Constant: int SORT_BY_PERSISTENCE
sort result set of getJobsList() by job persistence flag
Available since: 4.0


Constant: int SORT_BY_CREATION_TIME
sort result set of getJobsList() by job creation time
Available since: 4.0


Constant: int SORT_BY_SCHEDULE_TIME
sort result set of getJobsList() by job schedule time
Available since: 4.0


Constant: int SORT_BY_START_TIME
sort result set of getJobsList() by job start time
Available since: 4.0


Constant: int SORT_BY_END_TIME
sort result set of getJobsList() by job end time
Available since: 4.0


Constant: int SORT_ASC
sort result set of getJobsList() in direct order
Available since: 4.0


Constant: int SORT_DESC
sort result set of getJobsList() in reverse order
Available since: 4.0


Constant: int OK
constant to report completion status from the jobs using setCurrentJobStatus()
Available since: 4.0


Constant: int FAILED
constant to report completion status from the jobs using setCurrentJobStatus()
Available since: 4.0


Function: ZendJobQueue::__construct(string application=, string binding=taken from daemon_binding directive, int connection_timeout=taken from daemon_connection_timeout directive)
Creates a Zend_JobQueue object connected to a Job Queue daemon.

Parameters:
string application - an optional application name. All jobs created with this object will be associated with given application and only status of this job may be retrieved. Object created without application name can access any job.
string binding - an address of TCP or UNIX socket in PHP format (tcp://127.0.0.1:1234, unix:///tmp/jq, etc)
int connection_timeout - number of seconds to wait for connection before failure

Returns:
Available since: 4.0


Function: int ZendJobQueue::createHttpJob(string url, array vars, mixed options)
Creates new URL based job, to make the Job Queue daemon call given $script with given $vars

Parameters:
string url - an absolute URL of script to call
array vars - an associative array of variables which will be passed to script
mixed options - an associative array of additional options. The elements of this array can define job priority, predecessor, persistence, optional name, additional attributes of HTTP request as HTTP headers etc. The following options are supported: "name" - optional job name "priority" - job priority (see corresponding constants) "predecessor" - integer predecessor job id "persistent" - boolean (keep in history forever) "schedule_time" - time when job should be executed "schedule" - CRON-like scheduling command "http_headers" - array of additional HTTP headers

Returns: a job identifier which can be used to retrieve the job status
Available since: 4.0


Function: array ZendJobQueue::getJobStatus(int job_id)
Retrieves status of previously created job identified by $job_id.

Parameters:
int job_id - a job identifier

Returns: The array contains status, comletaion_status and output of the Job.
Available since: 4.0


Function: boolean ZendJobQueue::removeJob(int job_id)
Removes Job from queue. Makes all dependent jobs fail. In case Job is in progress it will be finished but dependent jobs won't be started anyway. For non-existing jobs the function just returns false. Finished jobs are simple removed from the database.

Parameters:
int job_id - a job identifier

Returns: job was removed or not
Available since: 4.0


Function: boolean ZendJobQueue::restartJob(int job_id)
Restart a previously executed Job and all its followers.

Parameters:
int job_id - a job identifier

Returns: if job was restarted or not
Available since: 4.0


Function: boolean ZendJobQueue::isSuspended()
Checks if Queue is suspended and returns true or false

Returns: a Job Queue status
Available since: 4.0


Function: static boolean ZendJobQueue::isJobQueueDaemonRunning()
Checks if the Job Queue daemon is running

Returns: Return true if the Job Queue deamon is running, false otherwise
Available since: 4.0


Function: ZendJobQueue::suspendQueue()
Suspends the Job Queue, so it will accept new Jobs, but won't start them. The jobs which were executed during call to this function will be completed

Returns:
Available since: 4.0


Function: ZendJobQueue::resumeQueue()
the Job Queue, so it will schedule and start queued jobs.

Returns:
Available since: 4.0


Function: array ZendJobQueue::getStatistics()
Returns internal daemon statistics like up-time, number of complete jobs, number of failed jobs, number of waiting jobs, number of currently running jobs, etc

Returns: associative array
Available since: 4.0


Function: array ZendJobQueue::getConfig()
Returns current value of configuration option of Job Queue daemon

Returns: associative array of configuration variables
Available since: 4.0


Function: boolean ZendJobQueue::reloadConfig()
Re-reads the configuration file of the Job Queue daemon and reloads all directives that are reloadable

Returns: if configuration file was loaded succesful or not
Available since: 4.0


Function: array ZendJobQueue::getJobInfo(int job_id)
Returns an associative array with properties of Job with given id from daemon database

Parameters:
int job_id - a job identifier

Returns: array of job details. The following properties are provided (some of them don't have to be always set): "id" - job identifier "type" - job type (see TYPE_* constants) "status" - job status (see STATUS_* constants) "priority" - job priority (see PRIORITY_* constants) "persistent" - persistence flag "script" - URL or SHELL script name "predecessor" - job predecessor "name" - job name "vars" - input variables or arguments "http_headers" - additional HTTP headers for HTTP jobs "output" - output of the job "error" - error output of the job "creation_time" - time when the job was created "start_time" - time when the job was started "end_time" - time when the job was finished "schedule" - CRON-like schedule command "schedule_time" - time when the job execution was scheduled "app_id" - application name
Available since: 4.0


Function: array ZendJobQueue::getDependentJobs(int job_id)
Returns a list of associative arrays with properties of Jobs which depend from the Job with given identifier

Parameters:
int job_id - a job identifier

Returns: list of jobs
Available since: 4.0


Function: array ZendJobQueue::getJobsList(array query, int total)
Returns a list of associative arrays with properties of Jobs which conform to a given query

Parameters:
array query - an associative array with query arguments The array may contain the following keys which restrict the resulting list: "app_id" - query only jobs which belong to given application "name" - query only jobs with given name "script" - query only jobs with script name similar to given one (SQL LIKE) "type" - query only jobs of the given types (bitset) "priority" - query only jobs with given priorities (bitset) "status" - query only jobs with given statuses (bitset) "rule_id" - query only jobs produced by given scheduling rule "scheduled_before" - query only jobs scheduled before given date "scheduled_after" - query only jobs scheduled after given date "executed_before" - query only jobs executed before given date "executed_after" - query only jobs executed after given date "sort_by" - sort by given field (see SORT_BY_* constants) "sort_direction" - sort direction (SORT_ASC or SORT_DESC) "start" - skip the given number of jobs "count" - retrieve only the given number of jobs (100 by default)
int total - output parameter which is set to the total number of jobs conforming to the given query ignoring "start" and "count" fields

Returns: list of jobs with their details
Available since: 4.0


Function: array ZendJobQueue::getApplications()
Returns an array of application names known by daemon

Returns: list of applications
Available since: 4.0


Function: array ZendJobQueue::getSchedulingRules()
Returns array of all registered scheduled rules. Each rule is represented by nested associative array with the following properties: "id" - scheduling rule identifier "status" - rule status (see STATUS_* constants) "type" - rule type (see TYPE_* constants) "priority" - priority of the jobs created by this rule "persistent" - persistence flag of the jobs created by this rule "script" - URL or script to run "name" - name of the jobs created by this rule "vars" - input variables or arguments "http_headers" - additional HTTP headers "schedule" - CRON-like schedule command "app_id" - application name associated with this rule and created jobs "last_run" - the last time the rule was run "next_run" - the next time the rule will run

Returns: list of scheduling rules
Available since: 4.0


Function: array ZendJobQueue::getSchedulingRule(int rule_id)
Returns associative array with the properties of scheduling rule identified by given argument. The list of the properties is the same as in getSchedulingRule()

Parameters:
int rule_id - rule identifier

Returns: information about the scheduling rule
Available since: 4.0


Function: boolean ZendJobQueue::deleteSchedulingRule(int rule_id)
Deletes scheduling rule identified by given $rule_id and scheduled jobs created by this rule

Parameters:
int rule_id - rule identifier

Returns: if scheduling rule was deleted or not
Available since: 4.0


Function: boolean ZendJobQueue::suspendSchedulingRule(int rule_id)
Suspends scheduling rule identified by given $rule_id and deletes scheduled jobs created by this rule

Parameters:
int rule_id - rule identifier

Returns: if scheduling rule was suspended or not
Available since: 4.0


Function: boolean ZendJobQueue::resumeSchedulingRule(int rule_id)
Resumes scheduling rule identified by given $rule_id and createa corresponding scheduled job

Parameters:
int rule_id - rule identifier

Returns: if scheduling rule was resumed or not
Available since: 4.0


Function: boolean ZendJobQueue::updateSchedulingRule(int rule_id, string script, array vars, array options)
Updates and reschedules existing scheduling rule

Parameters:
int rule_id - rule identifier
string script - URL to request
array vars - input variables
array options - the same as in createHttpJob()

Returns: if scheduling rule was updated or not
Available since: 4.0


Function: static array ZendJobQueue::getCurrentJobParams()
Decodes an array of input variables passed to HTTP job

Returns: job variables
Available since: 4.0


Function: static ZendJobQueue::setCurrentJobStatus(int completion, string msg)
Reports job completion status (OK or FAILED) back to daemon

Parameters:
int completion - job completion status (OK or FAILED)
string msg - optional explanation message

Returns:
Available since: 4.0

INI Directives:

zend_jobqueue.enable
Enables the Job Queue

Default value(s):
1:
Type: boolean
Measurement units:
Available since: 4.0

zend_jobqueue.daemon_connection_timeout
Default connection timeout to Job Queue daemon
Default connection timeout to Job Queue daemon. Can be overridden using a parameter to Zend_JobQueue ctor
Default value(s):
10:
Type: int
Measurement units: seconds
Available since: 4.0

zend_jobqueue.daemon_binding
Default binding to Job Queue daemon
Default binding to Job Queue daemon. Can be overridden using a parameter to Zend_JobQueue ctor
Default value(s):
tcp://127.0.0.1:55555: for: WindowsAll ,
unix://jobqueue.sock:
Type: string
Measurement units:
Available since: 4.0

zend_jobqueue.log_verbosity_level
The log verbosity level [0-5]
The extension's log verbosity level. Level 1 includes very important info messages, errors and warnings. Level 2 displays notices. Greater levels (up to 5) server debug purposes only.
Default value(s):
0:
Type: int
Measurement units:
Available since: 4.0

zend_jobqueue.log_rotation_size

The maximum size of the log file before it is rotated
Default value(s):
10:
Type: int
Measurement units: MBytes
Available since: 4.0