ambientia/queue-command

为 Symfony 项目提供异步队列

v2.0.2 2021-12-01 12:48 UTC

This package is auto-updated.

Last update: 2024-09-29 05:22:26 UTC


README

用于执行队列命令的 PHP 库

用法

添加到队列

<?php

use Ambientia\QueueCommand\QueueCommandEntity;
use App\MyModule\MyService;
use Doctrine\Common\Persistence\ObjectManager;


$queueCommand = new QueueCommandEntity();
$queueCommand->setService(MyService::class);

/** @var ObjectManager $entityManager */
$entityManager->persist($queueCommand);
$entityManager->flush();

创建队列命令

<?php
namespace App\MyModule;

class MyService
{
    public function execute(int $arg1)
    {

        //do some stuff
        $result = $arg1 + 1;

        // return some message if needed
        return "$arg1 processed ro $result";

    }
}

添加 cron

* * * * * ambientia:queue-command:execute >> /path/to/log/file 2>&1

添加数据清理器

https://github.com/alphpkeemik/data-cleaner

开发

运行 docker docker-composer up -d

bash 进入容器 docker/bash.sh

待办

  • 移除容器依赖
  • 待办 替换 merge 它在 EntityProcessor 中的 find
  • 待办 添加等待/持续运行
  • 添加数据清理器接口

运行代码修复器

运行 php cs fixer ./vendor/bin/php-cs-fixer fix

运行测试

使用 phpunit 运行测试 ./vendor/bin/phpunit

运行分析器

运行 phan ./vendor/bin/phan