This package is abandoned and no longer maintained. The author suggests using the traderinteractive/cronus package instead.

Process registry using MongoDB as a backend

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

Process registry using MongoDB as a backend.

Features

  • Automatic process cleaning when:
  • Process not running
  • User-given expire time elapses
  • Process id is reused
  • User-given process count limits
  • Across all hosts
  • Per host
  • Concurrent safety using an optimistic method
  • Resettable expire times

Simple example

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();

In this example the work is only being done by one process at one time despite how many of these scripts start, which is due to a max processes setting of 1.

A good setup is a collection of servers with these scripts run from a cron. Since the cron will continue to run the script trying the add() method, reliability is achieved should one fail (automatically cleaned up) or get stuck (automatically cleaned after 60 minutes).

Composer & Requirements

To add the library as a local, per-project dependency use Composer! Simply add a dependency on traderinteractive/cronus to your project's composer.json file such as:

composer require traderinteractive/cronus

In addition to the composer dependencies the project relies on procfs.

Documentation

Found in the source itself, take a look!

Contact

Developers may be contacted at:

Project build

Install and start mongodb. With a checkout of the code get Composer in your PATH and run:

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