Skip to content

Instantly share code, notes, and snippets.

@WyriHaximus
Created January 20, 2018 22:52
Show Gist options
  • Save WyriHaximus/9262cdba6da5e3a49baee7a59f0b05f0 to your computer and use it in GitHub Desktop.
Save WyriHaximus/9262cdba6da5e3a49baee7a59f0b05f0 to your computer and use it in GitHub Desktop.
<?php
use ApiClients\Client\Supervisord\AsyncClientInterface;
use ApiClients\Client\Supervisord\Resource\Async\Program;
use ApiClients\Client\Supervisord\Resource\ProgramInterface;
use Psr\Log\LoggerInterface;
use React\EventLoop\LoopInterface;
use Rx\React\Promise;
Promise::fromObservable(
$this->supervisor->programs()->filter(function (ProgramInterface $program) {
return $program->name() === getenv('SUPERVISOR_NAME');
})->take(1)
)->then(function (Program $program) {
$uptime = $program->now() - $program->start();
$this->logger->info('"' . $program->name() . '" has been up and running for ' . $uptime . ' seconds, restarting');
return $program->restart();
})->done(function (Program $program) {
$uptime = $program->now() - $program->start();
$this->logger->info('Restarted "' . $program->name() . '" up and running for ' . $uptime . ' seconds');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment