uafrica / delayed-jobs
A CakePHP Plugin to manage and process background jobs with priority and retries
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 74 437
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 11
Forks: 2
Open Issues: 6
Type:cakephp-plugin
Requires
- php: ^7.2
- cakephp/cakephp: ^4.0.2
- cakephp/migrations: ^3.0@beta
- php-amqplib/php-amqplib: ^2.11.0
Requires (Dev)
- cakephp/app: ^4.0
- cakephp/cakephp-codesniffer: ^4.0
- cakephp/debug_kit: ^4.0
- dereuromark/cakephp-ide-helper: ^1.0
- phpstan/phpstan: ^0.12.0
- phpunit/phpunit: ^8.5
Suggests
- dereuromark/cakephp-ide-helper: For maximum IDE support, especially around enqueue() usage.
- lampager/lampager-cakephp: To support paged archiving
- dev-master
- v10.3.0
- v10.2.0
- v10.1.3
- v10.1.2
- v10.1.1
- v10.1.0
- v10.0.3
- v10.0.2
- v10.0.1
- v10.0.0
- v9.1.1
- v9.1.0
- v9.0.4
- v9.0.3
- v9.0.2
- v9.0.1
- v9.0.0
- v8.0.0
- v7.5.1
- v7.5.0
- v7.4.2
- v7.4.1
- v7.4.0
- v7.3.2
- v7.3.1
- v7.3.0
- v7.2.2
- v7.2.1
- v7.2.0
- v7.1.0
- v7.0.3
- v7.0.2
- v7.0.1
- v7.0.0
- v6.7.0
- v6.6.0
- v6.5.2
- v6.5.1
- v6.5.0
- v6.4.8
- v6.4.7
- v6.4.6
- v6.4.5
- v6.4.4
- v6.4.3
- v6.4.2
- v6.4.1
- v6.4.0
- v6.3.7
- v6.3.6
- v6.3.5
- v6.3.4
- v6.3.3
- v6.3.2
- v6.3.1
- v6.3.0
- v6.2.2
- v6.2.1
- v6.2.0
- v6.1.4
- v6.1.3
- v6.1.2
- v6.1.1
- v6.1.0
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v5.4.2
- v5.4.1
- v5.4.0
- v5.3.3
- v5.3.2
- v5.3.1
- v5.3.0
- v5.2.1
- v5.2.0
- v5.1.1
- v5.1.0
- 5.0.x-dev
- v5.0.13
- v5.0.12
- v5.0.11
- v5.0.10
- v5.0.9
- v5.0.8
- v5.0.7
- v5.0.6
- v5.0.5
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.12
- v4.0.11
- v4.0.10
- v4.0.9
- v4.0.8
- v4.0.7
- v4.0.6
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.13
- v3.0.12
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- dev-dependabot/composer/phpstan/phpstan-tw-1.9.14
- dev-dependabot/composer/cakephp/cakephp-codesniffer-tw-5.0
- dev-dependabot/composer/php-amqplib/php-amqplib-tw-3.4.0
- dev-dependabot/composer/phpunit/phpunit-tw-9.5
- dev-dependabot/composer/php-amqplib/php-amqplib-tw-3.0.0
- dev-batch-processing
- dev-code-clean
- dev-archive-table
- dev-dashboard
- dev-experimental-worker-host
- dev-rollback
This package is auto-updated.
Last update: 2024-08-20 06:21:30 UTC
README
This delayed Jobs module was built by Jaco Roux for the uAfrica eCommerce Platform.
A plugin that allows you to load priority tasks for async processing. This is a scalable plugin that can be executed on multiple application servers to distribute the load. It uses a combination of a database and a RabbitMQ server to manage the job queue.
Requirements
- PHP 7.2+
- CakePHP 4.0+
- A database supported by CakePHP
- A RabbitMQ instance with the delayed message exchange plugin
Installation
- Require the plugin with composer
$ composer require uafrica/delayed-jobs
. - Load the plugin by running
bin/cake plugin load DelayedJobs
- Setup the database by running
bin/cake migrations migrate --plugin DelayedJobs
Running a worker
To run a single worker, run bin/cake worker -v
.
To run multiple workers, run bin/cake watchdog --workers x
(Where x is the number to run)
It is recommended to use something like SupervisorD to run multiple workers.
Enqueuing a job
$job = new \DelayedJob\DelayedJob\Job(); $job->setWorker('RunJob') //References a \App\Worker\RunJobWorker class ->setPayload($payload) //An array of payload data ->setRunAt(new Time('+1 hour')) //Run this job in an hour ->setPriority('10'); //Priority of 10 \DelayedJob\DelayedJob\JobManager::instance() ->enqueue($job);
Alternatively, you can use the \DelayedJob\DelayedJob\EnqueueTrait
which gives an
enqeue($worker, $payload, $options)
method.
Creating a worker
Simply create a class in the Worker
namespace that implements the \DelayedJob\Worker\JobWorkerInterface
For example
namespace DelayedJobs\Worker; use DelayedJobs\DelayedJob\Job; use DelayedJobs\Result\Success; /** * Class TestWorker */ class TestWorker implements JobWorkerInterface { /** * @param \DelayedJobs\DelayedJob\Job $job The job that is being run. * @return bool */ public function __invoke(Job $job) { return new Success('We ran!') } }