ZendHQ JobQueue

The ZendPHP PHP extension includes a JobQueue to schedule jobs, defer jobs, and to run recurring processes in PHP applications. ZendHQ can schedule jobs for both PHP and non-PHP workers, and it can use either the command line interface or HTTP calls.

Consider the following scenarios:

Use Case 1
Use Case 2
Use Case 3
Your application is processing images, aggregating data, performing complex data queries or transactions, generating reports, or similar, while the user is waiting.
During business hours, you need all computational power to handle your customer traffic.
Your application needs to fetch an hourly news feed. Or, you need daily or weekly or monthly reports. Or, you need to send daily announcements.
⇨ Use the JobQueue to defer such long-running processes to be able to return a response to the user right away.
⇨ Use the JobQueue to schedule all report generation to run only during low-traffic hours.
⇨ Use the JobQueue to schedule these jobs to be done automatically on a recurring schedule.

 

What is a job?

In heterogeneous environments, you may want to delegate work to other language runtimes or computational units.

  • A job is a task executed by the JobQueue, either a CLI command or an HTTP call. You can give a job a scheduled time or run it on a recurring schedule.

  • You assign each job a priority; if a queue contains multiple jobs, the jobs with the highest priority are executed first. Delayed jobs with an overdue schedule are bumped in priority.

  • Jobs are identified by numeric IDs. Historical job runs are identified by run IDs.

What is a job queue?

You can create named queues that group jobs and process them together.

  • Queues are identified by names or numeric IDs. Commands that accept queue names can also accept queue IDs. In case of ambiguity, the queue identifier can be prefixed with name: or id: to specify the type of the identifier.

  • You assign each queue a priority. If there are multiple queues, the jobs in the queue with the highest priority run first. In each queue, you can define defaults for job priority, timeout threshold, number of retries, and when to keep job output. Queues enable you to scale.

What is a Cron job?

A job that is scheduled to run at specific times or intervals. For more information, see ZendHQ JobQueue Crontab Syntax.

Architecture overview

To process queues and jobs, the PHP API for JobQueue communicates with the ZendHQ node.

Supported Features

Feature PHP API
(programmatic)
ZendHQ User Interface
(manual)
JSON-RPC API
(programmatic)
Create and delete queues
Suspend and resume queues
List queues
Schedule and query jobs
Cancel jobs
Create and view jobs
See scheduled jobs and job details
View job history
Create monitoring rules for job failures and errors

Limitations

  • In the current release, CLI jobs run only on the ZendHQ node itself.

  • HTTP jobs support only GET, POST, and PUT calls.

  • HTTP jobs must return a 200-299 range status code to be considered successful. 300-399 status codes from HTTP workers are not interpreted as successes.