php-resque/bin/resque

106 lines
2.3 KiB
Plaintext
Raw Normal View History

2010-04-18 13:58:43 +00:00
<?php
// Find and initialize Composer
$files = array(
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
);
$found = false;
foreach ($files as $file) {
if (file_exists($file)) {
require_once $file;
break;
}
}
if (!class_exists('Composer\Autoload\ClassLoader', false)) {
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}
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
$REDIS_BACKEND = getenv('REDIS_BACKEND');
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
2010-12-11 01:30:28 +00:00
if(!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB))
Resque::setBackend($REDIS_BACKEND);
else
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
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;
}
$APP_INCLUDE = getenv('APP_INCLUDE');
if($APP_INCLUDE) {
if(!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
}
require_once $APP_INCLUDE;
}
2010-04-18 13:58:43 +00:00
$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 = Resque::fork();
2010-04-18 13:58:43 +00:00
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;
$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
}
2010-04-18 13:58:43 +00:00
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
$worker->work($interval);
}
2010-12-11 01:30:28 +00:00
?>