long-running / long-running
Installs: 1 061 221
Dependents: 4
Suggesters: 0
Security: 0
Stars: 193
Watchers: 8
Forks: 18
Open Issues: 4
Requires
- php: ^8.0
- doctrine/orm: ^2.7.3
- psr/log: ^1.1 || ^2.0 || ^3.0
- sentry/sdk: ^3.1
- symfony/yaml: ^5.4 || ^6.0
Requires (Dev)
- doctrine/doctrine-bundle: ^2.5
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.2
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-symfony: ^1.0
- phpunit/phpunit: ^9.5.10
- sentry/sentry-symfony: ^4.0
- symfony/framework-bundle: ^5.4 || ^6.0
- symfony/phpunit-bridge: ^6.0
- symplify/easy-ci: ^10.0
- symplify/monorepo-builder: ^10.0
Replaces
- long-running/core: 1.1.0
- long-running/doctrine-orm: 1.1.0
- long-running/sentry: 1.1.0
- dev-main
- 1.1.0
- 1.0.1
- 1.0.0
- 1.0.0-RC1
- 0.x-dev
- 0.6.0
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- v0.1.1
- v0.1.0
- dev-dependabot/github_actions/shivammathur/setup-php-2.24.0
- dev-dependabot/github_actions/ramsey/composer-install-2.2.0
- dev-dependabot/github_actions/symplify/monorepo-split-github-action-2.2
- dev-monolog
This package is auto-updated.
Last update: 2024-09-15 16:18:27 UTC
README
This is the LongRunning mono repository for the following packages:
Installation
⚠️ Instead of installing this mono repository we recommend you to install the sub packages instead. See above.
composer require long-running/long-running
Symfony
If you are using Symfony, make sure to enable the bundle:
<?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
.
The LongRunning\Core\DelegatingCleaner
is aliased to LongRunning\Core\Cleaner
.
That means that you can inject the LongRunning\Core\Cleaner
service in your worker and it will
call all configured cleaners on cleanUp()
:
<?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:
Upgrading
If you are coming from LongRunning 0.5.0 please refer to UPGRADING.md.