Last active
April 14, 2017 17:48
-
-
Save Ocramius/530af20b1db06519967fa3100dc938fb to your computer and use it in GitHub Desktop.
A PHP long running process that fires a command at a command bus at regular time intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
declare(strict_types=1); | |
namespace CodeReviewsIo\Worker; | |
use CodeReviewsIo\Domain\Command\TickTime; | |
use Prooph\ServiceBus\CommandBus; | |
use React\EventLoop\Factory; | |
use Zend\ServiceManager\ServiceManager; | |
call_user_func(function () { | |
require_once __DIR__ . '/../vendor/autoload.php'; | |
set_time_limit(0); | |
$servicesConfig = require __DIR__ . '/../config/all-configs-merged-together.php'; | |
$loop = Factory::create(); | |
$tickInterval = 15 * 60; | |
$loop->addPeriodicTimer( | |
$tickInterval, | |
function () use ($servicesConfig) { | |
/* @var $commandBus callable */ | |
$commandBus = (new ServiceManager($servicesConfig)) | |
->get(CommandBus::class); | |
$commandBus(TickTime::fromCurrentPointInTime()); | |
// @TODO this is required, or connections will never be GC'd | |
gc_collect_cycles(); | |
} | |
); | |
$loop->run(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment