该软件包已被弃用且不再维护。作者建议使用 traderinteractive/cronus 软件包。

使用 MongoDB 作为后端处理注册表

v3.0.0 2018-02-22 15:50 UTC

This package is not auto-updated.

Last update: 2018-04-05 16:08:10 UTC


README

Build Status Code Quality Coverage Status

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

使用 MongoDB 作为后端处理注册表。

功能

  • 进程未运行时
  • 用户指定的过期时间已过
  • 进程 ID 被重复使用
  • 用户指定的进程数量限制
  • 跨所有主机
  • 按主机
  • 使用乐观方法进行并发安全
  • 可重置的过期时间

简单示例

use TraderInteractive\Cronus\ProcessRegistry;
use TraderInteractive\Cronus\ProcessInterface;

class MyProcess implements ProcessInterface
{
    public function getName() : string
    {
        return 'my-process';
    }

    public function getMinsBeforeExpire() : int
    {
        return 60;
    }

    public function getMaxGlobalProcesses() : int
    {
        return 1;
    }

    public function getMaxHostProcesses() : int
    {
        return 1;
    }

    public function run()
    {
        // do work that SHOULDN'T be done concurrently
    }
}

$mongo = new MongoClient();
$collection = $mongo->selectDB('testing')->selectCollection('processes');
$registry = new ProcessRegistry($collection);
$process = new MyProcess();

if (!$registry->add($process)) {
    return;
}

$process->run();

在这个示例中,尽管启动了这么多脚本,但只有一个进程在执行工作,这是因为设置了最大进程数为 1。

良好的设置是一组服务器,这些脚本由 cron 运行。由于 cron 将持续运行脚本并尝试使用 add() 方法,如果在执行过程中失败(将自动清理)或卡住(60 分钟后自动清理),则可以实现可靠性。

Composer & 需求

要作为本地项目依赖项添加库,请使用Composer!只需将 traderinteractive/cronus 作为依赖项添加到项目的 composer.json 文件中,例如

composer require traderinteractive/cronus

除了 Composer 依赖项外,项目还依赖于 procfs

文档

源代码中找到,请查看!

联系方式

开发者可通过以下方式联系:

项目构建

安装并启动 mongodb。使用代码的检查结果,在您的 PATH 中获取 Composer 并运行

./vendor/bin/phpunit
./vendor/bin/phpcs