3
3
4
4
// Find and initialize Composer
5
5
$ 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 ' ,
10
10
);
11
11
12
12
$ found = false ;
13
13
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
+ }
18
18
}
19
19
20
20
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
+ );
26
26
}
27
27
28
28
$ QUEUE = getenv ('QUEUE ' );
29
29
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" );
31
31
}
32
32
33
33
$ REDIS_BACKEND = getenv ('REDIS_BACKEND ' );
34
34
$ REDIS_BACKEND_DB = getenv ('REDIS_BACKEND_DB ' );
35
35
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 );
40
40
}
41
41
42
42
$ logLevel = 0 ;
43
43
$ LOGGING = getenv ('LOGGING ' );
44
44
$ VERBOSE = getenv ('VERBOSE ' );
45
45
$ VVERBOSE = getenv ('VVERBOSE ' );
46
46
if (!empty ($ LOGGING ) || !empty ($ VERBOSE )) {
47
- $ logLevel = Resque_Worker::LOG_NORMAL ;
47
+ $ logLevel = Resque_Worker::LOG_NORMAL ;
48
48
}
49
49
else if (!empty ($ VVERBOSE )) {
50
- $ logLevel = Resque_Worker::LOG_VERBOSE ;
50
+ $ logLevel = Resque_Worker::LOG_VERBOSE ;
51
51
}
52
52
53
53
$ APP_INCLUDE = getenv ('APP_INCLUDE ' );
54
54
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
+ }
58
58
59
- require_once $ APP_INCLUDE ;
59
+ require_once $ APP_INCLUDE ;
60
60
}
61
61
62
+ $ BLOCKING = getenv ('BLOCKING ' ) !== FALSE ;
63
+
62
64
$ interval = 5 ;
63
65
$ INTERVAL = getenv ('INTERVAL ' );
64
66
if (!empty ($ INTERVAL )) {
65
- $ interval = $ INTERVAL ;
67
+ $ interval = $ INTERVAL ;
66
68
}
67
69
68
70
$ count = 1 ;
69
71
$ COUNT = getenv ('COUNT ' );
70
72
if (!empty ($ COUNT ) && $ COUNT > 1 ) {
71
- $ count = $ COUNT ;
73
+ $ count = $ COUNT ;
72
74
}
73
75
74
76
$ PREFIX = getenv ('PREFIX ' );
@@ -78,35 +80,35 @@ if(!empty($PREFIX)) {
78
80
}
79
81
80
82
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
+ }
96
98
}
97
99
// Start a single worker
98
100
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 ;
102
104
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
+ }
108
110
109
- fwrite (STDOUT , '*** Starting worker ' .$ worker ."\n" );
110
- $ worker ->work ($ interval );
111
+ fwrite (STDOUT , '*** Starting worker ' .$ worker ."\n" );
112
+ $ worker ->work ($ interval, $ BLOCKING );
111
113
}
112
- ?>
114
+ ?>
0 commit comments