visual-craft / work-queue
使用Beanstalk的工作队列
v0.2.0
2022-06-08 13:30 UTC
Requires
- php: >=7.4.0
- pda/pheanstalk: ^4.0
- psr/log: ^1.0|^2.0|^3.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-08 18:39:35 UTC
README
使用Beanstalk的简单工作队列
安装
$ composer require visual-craft/work-queue
使用方法
创建队列管理器
use Pheanstalk\Pheanstalk; use VisualCraft\WorkQueue\Logger; use VisualCraft\WorkQueue\QueueManager; $manager = new QueueManager( Pheanstalk::create('127.0.0.1', 11300), 'some_queue', new Logger(null) );
设置队列处理程序和工作者
use VisualCraft\WorkQueue\QueueProcessor; use VisualCraft\WorkQueue\Worker\JobMetadata; use VisualCraft\WorkQueue\Worker\WorkerInterface; class SomeWorker implements WorkerInterface { public function work($payload, JobMetadata $metadata): void { // Process job } } // Create the queue processor and provide it with the worker $processor = new QueueProcessor( $manager, new SomeWorker(), ); // Process the queue while($processor->process()) {}
设置工作添加器并添加工作
$adder = new JobAdder($manager); $id = $adder->add('some data');
许可证
MIT