2010-04-18 13:58:43 +00:00
|
|
|
<?php
|
2010-12-11 01:30:28 +00:00
|
|
|
$QUEUE = getenv('QUEUE');
|
|
|
|
if(empty($QUEUE)) {
|
2010-04-18 13:58:43 +00:00
|
|
|
die("Set QUEUE env var containing the list of queues to work.\n");
|
|
|
|
}
|
|
|
|
|
2010-12-11 01:30:28 +00:00
|
|
|
$APP_INCLUDE = getenv('APP_INCLUDE');
|
|
|
|
if(!$APP_INCLUDE) {
|
|
|
|
if(!file_exists($APP_INCLUDE)) {
|
|
|
|
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-11 01:30:28 +00:00
|
|
|
require_once $APP_INCLUDE;
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require 'lib/Resque.php';
|
2010-04-19 00:35:50 +00:00
|
|
|
require 'lib/Resque/Worker.php';
|
2010-04-18 13:58:43 +00:00
|
|
|
|
2010-12-11 01:30:28 +00:00
|
|
|
$REDIS_BACKEND = getenv('REDIS_BACKEND');
|
|
|
|
if(!empty($REDIS_BACKEND)) {
|
|
|
|
Resque::setBackend($REDIS_BACKEND);
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$logLevel = 0;
|
2010-12-11 01:30:28 +00:00
|
|
|
$LOGGING = getenv('LOGGING');
|
|
|
|
$VERBOSE = getenv('VERBOSE');
|
|
|
|
$VVERBOSE = getenv('VVERBOSE');
|
|
|
|
if(!empty($LOGGING) || !empty($VERBOSE)) {
|
2010-04-18 13:58:43 +00:00
|
|
|
$logLevel = Resque_Worker::LOG_NORMAL;
|
|
|
|
}
|
2010-12-11 01:30:28 +00:00
|
|
|
else if(!empty($VVERBOSE)) {
|
2010-04-18 13:58:43 +00:00
|
|
|
$logLevel = Resque_Worker::LOG_VERBOSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
$interval = 5;
|
2010-12-11 01:30:28 +00:00
|
|
|
$INTERVAL = getenv('INTERVAL');
|
|
|
|
if(!empty($INTERVAL)) {
|
|
|
|
$interval = $INTERVAL;
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$count = 1;
|
2010-12-11 01:30:28 +00:00
|
|
|
$COUNT = getenv('COUNT');
|
|
|
|
if(!empty($COUNT) && $COUNT > 1) {
|
|
|
|
$count = $COUNT;
|
2010-04-18 13:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if($count > 1) {
|
|
|
|
for($i = 0; $i < $count; ++$i) {
|
|
|
|
$pid = pcntl_fork();
|
|
|
|
if($pid == -1) {
|
|
|
|
die("Could not fork worker ".$i."\n");
|
|
|
|
}
|
|
|
|
// Child, start the worker
|
|
|
|
else if(!$pid) {
|
2010-12-11 01:30:28 +00:00
|
|
|
$queues = explode(',', $QUEUE);
|
2010-04-18 13:58:43 +00:00
|
|
|
$worker = new Resque_Worker($queues);
|
|
|
|
$worker->logLevel = $logLevel;
|
|
|
|
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
|
|
|
|
$worker->work($interval);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Start a single worker
|
|
|
|
else {
|
2010-12-11 01:30:28 +00:00
|
|
|
$queues = explode(',', $QUEUE);
|
2010-04-18 13:58:43 +00:00
|
|
|
$worker = new Resque_Worker($queues);
|
|
|
|
$worker->logLevel = $logLevel;
|
|
|
|
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
|
|
|
|
$worker->work($interval);
|
|
|
|
}
|
2010-12-11 01:30:28 +00:00
|
|
|
?>
|