php-resque/resque.php

80 lines
1.7 KiB
PHP
Raw Normal View History

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) {
2010-12-11 01:30:28 +00:00
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_once 'lib/Resque.php';
require_once '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;
$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
?>