visual-craft / beanstalk-scheduler
此包最新版本(v0.1.1)没有可用的许可证信息。
使用Beanstalk进行后台作业调度
v0.1.1
2019-11-12 09:11 UTC
Requires
- php: >=5.5.0
- pda/pheanstalk: v3.0.0
- psr/log: 1.0.*@dev|~1.0
This package is auto-updated.
Last update: 2024-09-20 19:55:41 UTC
README
使用Beanstalk进行后台作业调度
安装
$ composer require visual-craft/beanstalk-scheduler
使用方法
// Create Beanstalkd connection
$connection = new \Pheanstalk\Pheanstalk('127.0.0.1');
// Add job
$manager = new \VisualCraft\BeanstalkScheduler\Manager($connection, 'some_queue');
$job = new \VisualCraft\BeanstalkScheduler\Job('some data');
$manager->submit($job);
// or
//$manager->submit($job, 60); // with the delay of 60 seconds
// Define worker
class SomeWorker implements \VisualCraft\BeanstalkScheduler\WorkerInterface
{
public function work(Job $job)
{
// do some work
// $job->getPayload() returns 'some data'
// you can reschedule failed job:
// throw new \VisualCraft\BeanstalkScheduler\Exception\RescheduleJobException();
}
public function isReschedulableException(\Exception $exception)
{
// Another way of rescheduling failed job
// Put some logic here
return true;
}
public function fail(Job $job)
{
// Optionally you can do something with failed job
}
}
// Process job
$scheduler = new \VisualCraft\BeanstalkScheduler\Scheduler($connection, 'some_queue');
$scheduler
->setWorker(new SomeWorker())
// Define rescheduling configuration:
->setReschedule([20, 30])
;
$scheduler->process();
许可证
此代码在MIT许可证下发布。完整的许可证请见文件:LICENSE