Add PIDFILE environment variable to write the PID of a single running worker out to a file

This commit is contained in:
chris.boulton 2011-03-27 16:01:35 +11:00
parent 0372a27ab7
commit 34de8e4307

View File

@ -5,7 +5,7 @@ if(empty($QUEUE)) {
} }
$APP_INCLUDE = getenv('APP_INCLUDE'); $APP_INCLUDE = getenv('APP_INCLUDE');
if(!$APP_INCLUDE) { if($APP_INCLUDE) {
if(!file_exists($APP_INCLUDE)) { if(!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n"); die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
} }
@ -66,6 +66,13 @@ else {
$queues = explode(',', $QUEUE); $queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues); $worker = new Resque_Worker($queues);
$worker->logLevel = $logLevel; $worker->logLevel = $logLevel;
$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
}
fwrite(STDOUT, '*** Starting worker '.$worker."\n"); fwrite(STDOUT, '*** Starting worker '.$worker."\n");
$worker->work($interval); $worker->work($interval);
} }