supervising the unsupervisable

As systems scale and react to growing user numbers, the way you use and transform your data changes. You'll probably build towards a system that works around processing queues, batch processing within daemons and pools of workers. There are many languages that are designed with this in mind, but in reality, we sometimes have to deal with this type of system in languages best suited to simpler tasks.

Four, Five, FIRE!

Supervising child processes can be difficult without the proper tools. Processes can fail unexpectedly, logically related scripts won't know their siblings have disappeared, and extra work will likely ensue. That's why we've written a simple library, aptly named Supervisor, in an attempt to supervise these processes within our PHP applications.

use Graze\Supervisor\ProcessSupervisor;  
use Symfony\Component\Process\Process;

$while = new Process('/usr/bin/python while_true.py');

$sup = new ProcessSupervisor($while);
$sup->start();
$sup->supervise();

This will run your while_true.py process and monitor its status. If the process terminates unexpectedly, the supervisor steps in and attempts to handle it as gracefully as possible. You can configure the supervisor to retry your process, notify your team via pagerduty, or add your own custom handlers.

To find out more about how to use the supervisor library to handle your processes, please read the documentation on github.

by Andrew Lawson

Find us on GitHub or follow us on Twitter.

Here at graze, we're always looking to hire smart people to join our tech team. If you love solving the types of technical challenges we face, send your CV to jobs@graze.com.

comments powered by Disqus