定制 codemonster-ru/queue 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codemonster-ru/queue

最新稳定版本:v1.0.0

Composer 安装命令:

composer require codemonster-ru/queue

包简介

Queue and job primitives for Annabel applications.

README 文档

README

Queue and job primitives for Annabel applications.

Usage

use Codemonster\Queue\Contracts\JobInterface;
use Codemonster\Queue\QueueManager;

final class SendWelcomeEmail implements JobInterface
{
    public function handle(): void
    {
        // Send the email.
    }
}

$manager = new QueueManager([
    'default' => 'sync',
    'connections' => [
        'sync' => [
            'driver' => 'sync',
        ],
    ],
]);

$manager->connection()->push(new SendWelcomeEmail());

The package ships with sync, database, and redis drivers. The Redis driver uses the PHP Redis extension when no explicit client object is configured:

$manager = new QueueManager([
    'default' => 'redis',
    'connections' => [
        'redis' => [
            'driver' => 'redis',
            'host' => '127.0.0.1',
            'port' => 6379,
            'database' => 0,
            'prefix' => 'queue:',
            'retry_after' => 60,
            'max_attempts' => 3,
        ],
    ],
]);

Database Driver

The database driver stores serialized jobs in a jobs table and can be processed by Worker:

use Codemonster\Queue\Contracts\WorkableQueueInterface;
use Codemonster\Queue\Worker;

/** @var WorkableQueueInterface $queue */
$queue = $manager->connection('database');
$queue->push(new SendWelcomeEmail());

(new Worker($queue))->workOnce();

Jobs can override their retry policy and timeout through JobOptionsInterface:

use Codemonster\Queue\Contracts\JobOptionsInterface;

final class SendWelcomeEmail implements JobOptionsInterface
{
    public function handle(): void
    {
        // Send the email.
    }

    public function maxAttempts(): int
    {
        return 5;
    }

    public function backoff(): int|array
    {
        return [10, 30, 120];
    }

    public function timeout(): int
    {
        return 30;
    }
}

Timeouts require the PCNTL extension. A backoff array uses the delay matching the current attempt and keeps using its last value for later attempts.

Failed jobs stored by the database driver can be inspected and retried:

$failed = $manager->failedJobs('database');

foreach ($failed->all() as $job) {
    echo $job->id() . ': ' . $job->exception();
}

$failed->retry('1');
$failed->retryAll();
$failed->flush();

Jobs should contain serializable data. Runtime services such as PDO connections should be resolved inside handle() by the application container or another application-level dependency mechanism.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固