mle86/wq-beanstalkd

用于 mle86/wq 的 Beanstalkd 模块,使用 pda/pheanstalk 连接器

v1.0.3 2020-06-18 13:53 UTC

This package is auto-updated.

Last update: 2024-09-18 22:41:10 UTC


README

此包包含 PHP 类 mle86\WQ\WorkServerAdapter\BeanstalkdWorkServer

它通过实现其 WorkServerAdapter 接口来补充 mle86/wq 包。

它通过 Paul Annesley 的 pda/pheanstalk 包连接到 Beanstalkd 服务器。

版本和兼容性

这是 版本 1.0.2mle86/wq-beanstalkd

它是为 mle86/wq 的 1.0.0 版本开发的,应与所有未来的 1.x 版本兼容。

安装和依赖

$ composer require mle86/wq-beanstalkd

它需要 PHP 7.1、mle86/wqpda/pheanstalk

类参考

class mle86\WQ\WorkServerAdapter\BeanstalkdWorkServer implements WorkServerAdapter

getNextQueueEntry() 使用 RESERVE 命令,buryEntry() 使用 BURY 命令,storeJob()requeueEntry() 使用 PUT 命令,而 deleteEntry() 使用 DELETE 命令。

工作队列 是 Beanstalkd 的“管子”。

  • public function __construct (Pheanstalk $pheanstalk)
    构造函数。接受一个已配置的 Pheanstalk 实例以进行操作。不尝试自己建立连接 - 使用 connect() 工厂方法代替。
  • public static function connect (string $host = "localhost", int $port = PheanstalkInterface::DEFAULT_PORT, int $connectTimeout = null)
    工厂方法。有关参数描述,请参阅 Pheanstalk::__construct

WorkServerAdapter 接口中文档化的接口方法

  • public function storeJob (string $workQueue, Job $job, int $delay = 0)
  • public function getNextQueueEntry ($workQueue, int $timeout = DEFAULT_TIMEOUT) : ?QueueEntry
  • public function buryEntry (QueueEntry $entry)
  • public function requeueEntry (QueueEntry $entry, int $delay, string $workQueue = null)
  • public function deleteEntry (QueueEntry $entry)

使用示例

<?php
use mle86\WQ\WorkServerAdapter\BeanstalkdWorkServer;
use mle86\WQ\WorkProcessor;
use mle86\WQ\Job\Job;

$processor = new WorkProcessor( BeanstalkdWorkServer::connect("localhost") );

while (true) {
    $processor->processNextJob("mail", function(Job $job) {
        $job->...;
    });
}

此操作将无限期地执行本地 Beanstalkd 服务器中“mail”管子中可用的所有作业。但是,如果其中一个作业抛出异常,它将中止 - 您可能希望在 processNextJob() 调用周围添加一个日志 try-catch 块,如 WQ 的“快速入门”示例 中所示。