Download the PHP package libcast/jobqueue without Composer
On this page you can find all versions of the php package libcast/jobqueue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download libcast/jobqueue
More information about libcast/jobqueue
Files in libcast/jobqueue
Package jobqueue
Short Description JobQueue is a PHP component that queues `tasks` defining `jobs` which can be executed by asynchronous and/or distributed `workers`
License MIT
Homepage https://github.com/bricev/JobQueue
Informations about the package jobqueue
PHP JobQueue component
Simple Job/Queue PHP component to help applications distribute Tasks through multiple workers.
Install
This package is installable and auto-loadable via Composer:
The application proposes a webservice and two CLIs. Read bellow for more documentation.
Configuration
- PHP 7.1 must be installed
- Redis must be installed (for queue data persistence)
- the
JOBQUEUE_ENV
environment variable may be set asdev
,prod
(or any string, default if not set:dev
) - the
JOBQUEUE_REDIS_DSN
environment variable must define the Redis DSN (eg. 'tcp://127.0.0.1:6379')
Usage
Defining a job
A job
holds the code that will be executed for tasks by a worker.
Each job must be defined in a PHP class that implements the ExecutableJob
interface:
Note: ExecutableJob
interface extends the LoggerAwareInterface
that can be used to set a logger.
This documentation provides more information about PSR-3 Log interfaces.
Tip: Package psr/log
(repo) can be added to a composer project by running this command:
The \Psr\Log\LoggerAwareTrait
can be used to easily add a logger setter and be compliant with the LoggerAwareInterface
.
Defining a task
Creating a task
requires the following elements:
- a
profile
- it can be anything, it regroups tasks into queue partitions, so that the JobQueueworker
app can consume tasks from one (only) profile - a
job
- which holds the code that has to be executed for the task - optional
parameters
that can be used by the job during its execution
To define a task in PHP:
Adding tasks to the queue
First, the queue has to be instantiated.
This can be done manually:
Or by using the ServiceContainer (this requires the proper configuration, see Configuration
section above):
Then, tasks can be enqueued easily:
The task's job will be executed as soon as a worker starts consuming the task's profile.
This component embeds a PHP executable worker.
See the CLI
section to get more details about its usage.
Worker events
The worker emits some events that can be listened to:
Event name | Description | Event attributes |
---|---|---|
worker.start |
Fired on worker launch | $event->getWorker() |
worker.finished |
Fired once the worker has finished running | $event->getWorker() |
task.fetched |
Fired each time a task is fetched from queue by the worker | $event->getTask() |
task.executed |
Fired when a task's job execution has been successful done | $event->getTask() |
task.failed |
Fired when a task's job execution fails | $event->getTask() |
To intercept an event, you can use the EventDispatcher
from the service container:
CLI
Those features require the proper configuration, see Configuration
section above.
The manager
app can be used to perform CRUD operations on tasks.
Usage:
The worker
app can be used to consume enqueued tasks.
Usage:
The worker
app can be used as an OS service (eg. upstart, systemd... on unix) to run on servers.
Webservice
Configuration
A web server should be configured to serve public/index.php
as a router script.
This feature requires the proper configuration, see Configuration
section above.
API
List all tasks:
Returns an array of tasks:
Errors:
400 Bad Request
if one of the parameters is wrong:Status "foo" does not exists
is status is not equal towaiting|running|finished|failed
Profile name only allows lowercase alphanumerical, dash and underscore characters
is profile is malformedImpossible to order by "foobar"
is order is not equal todate|profile|status
500 Internal Server Error
in case of a technical error
Get a task information:
Returns the task definition:
Errors:
404 Not Found
if no task correspond to the identifier500 Internal Server Error
in case of a technical error
Create a new task:
Returns the task definition:
Errors:
400 Bad Request
if the JSON body is malformed:Missing job
if the JSON object miss ajob
value.Missing profile
if the JSON object miss aprofile
value.Profile name only allows lowercase alphanumerical, dash and underscore characters
is profile is malformedMalformed parameters
is theparameters
value from the JSON object is not a key/value array
500 Internal Server Error
in case of a technical error
Tests
First, a Redis server must run locally (127.0.0.1 on 6379 port).
Then, to run tests, use the following command:
The MIT License (MIT). Please see LICENSE for more information.
All versions of jobqueue with dependencies
http-interop/response-sender Version ^1.0
middlewares/error-handler Version ^1.0
middlewares/fast-route Version ^1.0
middlewares/payload Version ^1.0
middlewares/request-handler Version ^1.0
predis/predis Version ^1.0
psr/log Version ^1.0
ramsey/uuid Version ^3.0
relay/relay Version ^2.0
symfony/config Version ^4.0
symfony/console Version ^4.0
symfony/dependency-injection Version ^4.0
symfony/event-dispatcher Version ^4.0
symfony/yaml Version ^4.0
vlucas/phpdotenv Version ^2.0
zendframework/zend-diactoros Version ^1.0