buzzingpixel/corbomite-queue

此包的最新版本(1.4.1)没有可用的许可信息。

Corbomite 队列

1.4.1 2019-06-05 19:22 UTC

This package is auto-updated.

Last update: 2024-09-06 07:07:35 UTC


README

是BuzzingPixel的Corbomite项目的一部分。

本项目提供了一种队列,用于将项目按顺序添加到服务器执行。

用法

当您需要将其添加到Corbomite项目时,CLI命令和依赖注入配置将自动设置。

安装

Corbomite Queue需要添加一些数据库表才能正常工作。为了做到这一点,它需要创建一些迁移,然后需要运行这些迁移。运行create-migrations命令,该命令将在您的Corobomite项目中放置迁移文件。

php app queue/create-migrations

运行该命令后,您需要运行迁移

php app migrate/up

运行队列

开发环境

在开发中,您可能只是想手动运行队列。执行此操作的命令是

php app queue/run

该命令运行队列中的下一个项目。

生产环境

从1.3.0版本开始,Corbomite Queue支持多个工作者。这意味着您可以并且应该有多个工作者在循环中运行队列/run命令(工作者的数量取决于您的服务器环境有多强大以及您想要消耗多少队列资源)。队列跟踪正在运行和未运行的批次。下一个工作者将选择下一个未表明正在运行的任务批次。

此存储库提供了一个用于Linux环境的示例shell脚本。 示例Shell脚本

鼓励您使用Supervisor来设置多个工作者运行此脚本。

添加到队列

队列API提供了极其简单的添加项目到队列的方法。请注意,在下面的示例中,您指定的任何类,Corbomite Queue都将尝试从依赖注入器中获取它,以便您可以使用依赖注入。

<?php
declare(strict_types=1);

use corbomite\di\Di;
use corbomite\queue\QueueApi;

/** @noinspection PhpUnhandledExceptionInspection */
$queueApi = Di::diContainer()->get(QueueApi::class);

$batchModel = $queueApi->makeActionQueueBatchModel([
    'name' => 'this_is_a_test',
    'title' => 'This is a Test',
    'items' => [
        $queueApi->makeActionQueueItemModel([
            'class' => \some\ClassThing::class,
        ]),
        $queueApi->makeActionQueueItemModel([
            'class' => \another\ClassThing::class,
        ]),
        $queueApi->makeActionQueueItemModel([
            'class' => \more\Classes::class,
            'method' => 'someMethod', // If method is not specified, --invoke is assumed
            // Provide anything you want in this array, your method will receive it as an argument
            'context' => [
                'stuff' => 'thing',
            ],
        ]),
    ],
]);

/** @noinspection PhpUnhandledExceptionInspection */
$queueApi->addToQueue($batchModel);

许可

版权所有 2019 BuzzingPixel, LLC

根据Apache License,版本2.0(“许可证”);除非根据适用法律或书面同意,否则不得使用此文件,除非符合许可证。您可以在以下位置获得许可证副本: https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言管理权限和限制,请参阅许可证。