Introduce the 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 (CLI) or HTTP calls.
Consider the following scenarios:
What is a job?
In heterogeneous environments, you may want to delegate work to other language runtimes or computational units. We call these work items jobs.
-
A job is a task that is run 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 run 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:
orid:
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 cron job is a job that is scheduled to run at specific times or intervals. For more information, see Specify dates and times using 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 | ✅ | ✅ | ✅ |
View 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 status code in the range of 200 to 299 to be considered successful. The status codes from HTTP workers in the range of 300 to 399 are not interpreted as successes.