uafrica/delayed-jobs
最新稳定版本:v10.3.0
Composer 安装命令:
composer require uafrica/delayed-jobs
包简介
A CakePHP Plugin to manage and process background jobs with priority and retries
README 文档
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!') } }
统计信息
- 总下载量: 74.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-11