2017 © Pedro Peláez
 

library long-running

Tools for working with long-running processes

image

long-running/long-running

Tools for working with long-running processes

  • Tuesday, December 5, 2017
  • by cmodijk
  • Repository
  • 6 Watchers
  • 112 Stars
  • 67,728 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 8 Forks
  • 5 Open issues
  • 6 Versions
  • 18 % Grown

The README.md

LongRunning

Tests, (*1)

This is the LongRunning mono repository for the following packages:, (*2)

Installation

:warning: Instead of installing this mono repository we recommend you to install the sub packages instead. See above., (*3)

composer require long-running/long-running

Symfony

If you are using Symfony, make sure to enable the bundle:, (*4)

<?php
// config/bundles.php

return [
    // ...
    LongRunning\Core\Bundle\LongRunningBundle::class => ['all' => true],
];

How to use?

<?php

final class MyCleaner implements \LongRunning\Core\Cleaner
{
    public function cleanUp() : void
    {
        echo "Cleaning up memory!";
    }
}

$cleaner = new \LongRunning\Core\DelegatingCleaner([
    new MyCleaner(),
]);

while (true) {
    // Do heavy work, like processing jobs from a queue
    echo "Doing heavy work";
    sleep(1);
    echo "Done with heavy work";

    // Cleanup things
    $cleaner->cleanUp();
}

If you are using Symfony, any service that implements the LongRunning\Core\Cleaner interface will be autoconfigured and added to the LongRunning\Core\DelegatingCleaner., (*5)

The LongRunning\Core\DelegatingCleaner is aliased to LongRunning\Core\Cleaner., (*6)

That means that you can inject the LongRunning\Core\Cleaner service in your worker and it will call all configured cleaners on cleanUp():, (*7)

<?php

namespace App;

use LongRunning\Core\Cleaner;

final class Worker
{
    private Cleaner $cleaner;

    public function __construct(Cleaner $cleaner)
    {
        $this->cleaner = $cleaner;
    }

    public function doWork() : void
    {
        while (true) {
            // Do heavy work, like processing jobs from a queue
            echo "Doing heavy work";
            sleep(1);
            echo "Done with heavy work";

            // Cleanup things
            $this->cleaner->cleanUp();
        }
    }
}

Existing cleaners

LongRunning provides 2 packages that add additional cleaners:, (*8)

Upgrading

If you are coming from LongRunning 0.5.0 please refer to UPGRADING.md., (*9)

The Versions