php-resque/bin/resque

121 lines
3.1 KiB
Plaintext
Raw Normal View History

2013-03-13 11:41:32 +00:00
#!/usr/bin/env php
2010-04-18 13:58:43 +00:00
<?php
// Find and initialize Composer
$files = array(
2013-06-03 16:09:54 +00:00
__DIR__ . '/../../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
);
$found = false;
foreach ($files as $file) {
2013-06-03 16:09:54 +00:00
if (file_exists($file)) {
require_once $file;
break;
}
}
if (!class_exists('Composer\Autoload\ClassLoader', false)) {
2013-06-03 16:09:54 +00:00
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)) {
2013-06-03 16:09:54 +00:00
die("Set QUEUE env var containing the list of queues to work.\n");
2010-04-18 13:58:43 +00:00
}
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)) {
2013-06-03 16:09:54 +00:00
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 = false;
2010-12-11 01:30:28 +00:00
$LOGGING = getenv('LOGGING');
$VERBOSE = getenv('VERBOSE');
$VVERBOSE = getenv('VVERBOSE');
if(!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = true;
2010-04-18 13:58:43 +00:00
}
2010-12-11 01:30:28 +00:00
else if(!empty($VVERBOSE)) {
$logLevel = true;
2010-04-18 13:58:43 +00:00
}
$APP_INCLUDE = getenv('APP_INCLUDE');
if($APP_INCLUDE) {
2013-06-03 16:09:54 +00:00
if(!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
}
2013-06-03 16:09:54 +00:00
require_once $APP_INCLUDE;
}
// See if the APP_INCLUDE containes a logger object,
// If none exists, fallback to internal logger
if (!isset($logger) && !is_object($logger)) {
$logger = new Resque_Log($logLevel);
}
2013-06-03 16:09:54 +00:00
$BLOCKING = getenv('BLOCKING') !== FALSE;
2010-04-18 13:58:43 +00:00
$interval = 5;
2010-12-11 01:30:28 +00:00
$INTERVAL = getenv('INTERVAL');
if(!empty($INTERVAL)) {
2013-06-03 16:09:54 +00:00
$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) {
2013-06-03 16:09:54 +00:00
$count = $COUNT;
2010-04-18 13:58:43 +00:00
}
$PREFIX = getenv('PREFIX');
if(!empty($PREFIX)) {
$logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $PREFIX));
Resque_Redis::prefix($PREFIX);
}
2010-04-18 13:58:43 +00:00
if($count > 1) {
2013-06-03 16:09:54 +00:00
for($i = 0; $i < $count; ++$i) {
$pid = Resque::fork();
if($pid == -1) {
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i));
die();
2013-06-03 16:09:54 +00:00
}
// Child, start the worker
else if(!$pid) {
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->setLogger($logger);
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
2013-06-03 16:09:54 +00:00
$worker->work($interval, $BLOCKING);
break;
}
}
2010-04-18 13:58:43 +00:00
}
// Start a single worker
else {
2013-06-03 16:09:54 +00:00
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker->setLogger($logger);
2013-06-03 16:09:54 +00:00
$PIDFILE = getenv('PIDFILE');
if ($PIDFILE) {
file_put_contents($PIDFILE, getmypid()) or
die('Could not write PID information to ' . $PIDFILE);
}
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker));
2013-06-03 16:09:54 +00:00
$worker->work($interval, $BLOCKING);
2010-04-18 13:58:43 +00:00
}
2013-06-03 16:09:54 +00:00
?>