Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 80 lines (69 sloc) 1.726 kB
cb4205d @chrisboulton Initial commit
authored
1 <?php
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
2 $QUEUE = getenv('QUEUE');
3 if(empty($QUEUE)) {
cb4205d @chrisboulton Initial commit
authored
4 die("Set QUEUE env var containing the list of queues to work.\n");
5 }
6
1a5564d @andrewjshults Switch to using require_once since it seems there are some conflicts …
andrewjshults authored
7 require_once 'lib/Resque.php';
8 require_once 'lib/Resque/Worker.php';
cb4205d @chrisboulton Initial commit
authored
9
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
10 $REDIS_BACKEND = getenv('REDIS_BACKEND');
11 if(!empty($REDIS_BACKEND)) {
12 Resque::setBackend($REDIS_BACKEND);
cb4205d @chrisboulton Initial commit
authored
13 }
14
15 $logLevel = 0;
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
16 $LOGGING = getenv('LOGGING');
17 $VERBOSE = getenv('VERBOSE');
18 $VVERBOSE = getenv('VVERBOSE');
19 if(!empty($LOGGING) || !empty($VERBOSE)) {
cb4205d @chrisboulton Initial commit
authored
20 $logLevel = Resque_Worker::LOG_NORMAL;
21 }
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
22 else if(!empty($VVERBOSE)) {
cb4205d @chrisboulton Initial commit
authored
23 $logLevel = Resque_Worker::LOG_VERBOSE;
24 }
25
2c5e088 @chrisboulton move include for resque before APP_INCLUDE is loaded in, so that way …
authored
26 $APP_INCLUDE = getenv('APP_INCLUDE');
27 if($APP_INCLUDE) {
28 if(!file_exists($APP_INCLUDE)) {
29 die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
30 }
31
32 require_once $APP_INCLUDE;
33 }
34
cb4205d @chrisboulton Initial commit
authored
35 $interval = 5;
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
36 $INTERVAL = getenv('INTERVAL');
37 if(!empty($INTERVAL)) {
38 $interval = $INTERVAL;
cb4205d @chrisboulton Initial commit
authored
39 }
40
41 $count = 1;
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
42 $COUNT = getenv('COUNT');
43 if(!empty($COUNT) && $COUNT > 1) {
44 $count = $COUNT;
cb4205d @chrisboulton Initial commit
authored
45 }
46
47 if($count > 1) {
48 for($i = 0; $i < $count; ++$i) {
49 $pid = pcntl_fork();
50 if($pid == -1) {
51 die("Could not fork worker ".$i."\n");
52 }
53 // Child, start the worker
54 else if(!$pid) {
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
55 $queues = explode(',', $QUEUE);
cb4205d @chrisboulton Initial commit
authored
56 $worker = new Resque_Worker($queues);
57 $worker->logLevel = $logLevel;
58 fwrite(STDOUT, '*** Starting worker '.$worker."\n");
59 $worker->work($interval);
60 break;
61 }
62 }
63 }
64 // Start a single worker
65 else {
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
66 $queues = explode(',', $QUEUE);
cb4205d @chrisboulton Initial commit
authored
67 $worker = new Resque_Worker($queues);
68 $worker->logLevel = $logLevel;
34de8e4 @chrisboulton Add PIDFILE environment variable to write the PID of a single running…
authored
69
70 $PIDFILE = getenv('PIDFILE');
71 if ($PIDFILE) {
72 file_put_contents($PIDFILE, getmypid()) or
73 die('Could not write PID information to ' . $PIDFILE);
74 }
75
cb4205d @chrisboulton Initial commit
authored
76 fwrite(STDOUT, '*** Starting worker '.$worker."\n");
77 $worker->work($interval);
78 }
f0a4990 @hobodave Refactors $_ENV to getenv
hobodave authored
79 ?>
Something went wrong with that request. Please try again.