Skip to content

Commit 59f617e

Browse files
committed
Merge pull request #63 from ruudk/blocking-list-pop
Basic support for blocking list pop
2 parents 8346fb8 + a0eaac4 commit 59f617e

File tree

16 files changed

+713
-194
lines changed

16 files changed

+713
-194
lines changed

bin/resque

100644100755
Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,74 @@
33

44
// Find and initialize Composer
55
$files = array(
6-
__DIR__ . '/../../vendor/autoload.php',
7-
__DIR__ . '/../../../autoload.php',
8-
__DIR__ . '/../../../../autoload.php',
9-
__DIR__ . '/../vendor/autoload.php',
6+
__DIR__ . '/../../vendor/autoload.php',
7+
__DIR__ . '/../../../autoload.php',
8+
__DIR__ . '/../../../../autoload.php',
9+
__DIR__ . '/../vendor/autoload.php',
1010
);
1111

1212
$found = false;
1313
foreach ($files as $file) {
14-
if (file_exists($file)) {
15-
require_once $file;
16-
break;
17-
}
14+
if (file_exists($file)) {
15+
require_once $file;
16+
break;
17+
}
1818
}
1919

2020
if (!class_exists('Composer\Autoload\ClassLoader', false)) {
21-
die(
22-
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
23-
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
24-
'php composer.phar install' . PHP_EOL
25-
);
21+
die(
22+
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
23+
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
24+
'php composer.phar install' . PHP_EOL
25+
);
2626
}
2727

2828
$QUEUE = getenv('QUEUE');
2929
if(empty($QUEUE)) {
30-
die("Set QUEUE env var containing the list of queues to work.\n");
30+
die("Set QUEUE env var containing the list of queues to work.\n");
3131
}
3232

3333
$REDIS_BACKEND = getenv('REDIS_BACKEND');
3434
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
3535
if(!empty($REDIS_BACKEND)) {
36-
if (empty($REDIS_BACKEND_DB))
37-
Resque::setBackend($REDIS_BACKEND);
38-
else
39-
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
36+
if (empty($REDIS_BACKEND_DB))
37+
Resque::setBackend($REDIS_BACKEND);
38+
else
39+
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
4040
}
4141

4242
$logLevel = 0;
4343
$LOGGING = getenv('LOGGING');
4444
$VERBOSE = getenv('VERBOSE');
4545
$VVERBOSE = getenv('VVERBOSE');
4646
if(!empty($LOGGING) || !empty($VERBOSE)) {
47-
$logLevel = Resque_Worker::LOG_NORMAL;
47+
$logLevel = Resque_Worker::LOG_NORMAL;
4848
}
4949
else if(!empty($VVERBOSE)) {
50-
$logLevel = Resque_Worker::LOG_VERBOSE;
50+
$logLevel = Resque_Worker::LOG_VERBOSE;
5151
}
5252

5353
$APP_INCLUDE = getenv('APP_INCLUDE');
5454
if($APP_INCLUDE) {
55-
if(!file_exists($APP_INCLUDE)) {
56-
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
57-
}
55+
if(!file_exists($APP_INCLUDE)) {
56+
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
57+
}
5858

59-
require_once $APP_INCLUDE;
59+
require_once $APP_INCLUDE;
6060
}
6161

62+
$BLOCKING = getenv('BLOCKING') !== FALSE;
63+
6264
$interval = 5;
6365
$INTERVAL = getenv('INTERVAL');
6466
if(!empty($INTERVAL)) {
65-
$interval = $INTERVAL;
67+
$interval = $INTERVAL;
6668
}
6769

6870
$count = 1;
6971
$COUNT = getenv('COUNT');
7072
if(!empty($COUNT) && $COUNT > 1) {
71-
$count = $COUNT;
73+
$count = $COUNT;
7274
}
7375

7476
$PREFIX = getenv('PREFIX');
@@ -78,35 +80,35 @@ if(!empty($PREFIX)) {
7880
}
7981

8082
if($count > 1) {
81-
for($i = 0; $i < $count; ++$i) {
82-
$pid = Resque::fork();
83-
if($pid == -1) {
84-
die("Could not fork worker ".$i."\n");
85-
}
86-
// Child, start the worker
87-
else if(!$pid) {
88-
$queues = explode(',', $QUEUE);
89-
$worker = new Resque_Worker($queues);
90-
$worker->logLevel = $logLevel;
91-
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
92-
$worker->work($interval);
93-
break;
94-
}
95-
}
83+
for($i = 0; $i < $count; ++$i) {
84+
$pid = Resque::fork();
85+
if($pid == -1) {
86+
die("Could not fork worker ".$i."\n");
87+
}
88+
// Child, start the worker
89+
else if(!$pid) {
90+
$queues = explode(',', $QUEUE);
91+
$worker = new Resque_Worker($queues);
92+
$worker->logLevel = $logLevel;
93+
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
94+
$worker->work($interval, $BLOCKING);
95+
break;
96+
}
97+
}
9698
}
9799
// Start a single worker
98100
else {
99-
$queues = explode(',', $QUEUE);
100-
$worker = new Resque_Worker($queues);
101-
$worker->logLevel = $logLevel;
101+
$queues = explode(',', $QUEUE);
102+
$worker = new Resque_Worker($queues);
103+
$worker->logLevel = $logLevel;
102104

103-
$PIDFILE = getenv('PIDFILE');
104-
if ($PIDFILE) {
105-
file_put_contents($PIDFILE, getmypid()) or
106-
die('Could not write PID information to ' . $PIDFILE);
107-
}
105+
$PIDFILE = getenv('PIDFILE');
106+
if ($PIDFILE) {
107+
file_put_contents($PIDFILE, getmypid()) or
108+
die('Could not write PID information to ' . $PIDFILE);
109+
}
108110

109-
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
110-
$worker->work($interval);
111+
fwrite(STDOUT, '*** Starting worker '.$worker."\n");
112+
$worker->work($interval, $BLOCKING);
111113
}
112-
?>
114+
?>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"require": {
2121
"php": ">=5.3.0",
2222
"ext-pcntl": "*",
23-
"colinmollenhour/credis": "dev-master"
23+
"colinmollenhour/credis": "1.2.*"
2424
},
2525
"suggest": {
2626
"ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker.",

0 commit comments

Comments
 (0)