@@ -51,27 +51,34 @@ If you're not familiar with Composer, please see <http://getcomposer.org/>.
51
51
52
52
1 . Add php-resque to your application's composer.json.
53
53
54
+ ``` json
55
+
54
56
{
55
57
...
56
58
"require" : {
57
59
"chrisboulton/php-resque" : " 1.2.x"
58
60
},
59
61
...
60
62
}
63
+ ```
61
64
62
65
2 . Run ` composer install ` .
63
66
64
67
3 . If you haven't already, add the Composer autoload to your project's
65
68
initialization file. (example)
66
69
70
+ ``` sh
67
71
require ' vendor/autoload.php' ;
72
+ ```
68
73
69
74
## Jobs ##
70
75
71
76
### Queueing Jobs ###
72
77
73
78
Jobs are queued as follows:
74
79
80
+ ``` php
81
+
75
82
// Required if redis is located elsewhere
76
83
Resque::setBackend('localhost:6379');
77
84
@@ -80,10 +87,14 @@ Jobs are queued as follows:
80
87
);
81
88
Resque::enqueue('default', 'My_Job', $args);
82
89
90
+ ```
91
+
83
92
### Defining Jobs ###
84
93
85
94
Each job should be in it's own class, and include a ` perform ` method.
86
95
96
+ ``` php
97
+
87
98
class My_Job
88
99
{
89
100
public function perform()
@@ -93,6 +104,8 @@ Each job should be in it's own class, and include a `perform` method.
93
104
}
94
105
}
95
106
107
+ ```
108
+
96
109
When the job is run, the class will be instantiated and any arguments
97
110
will be set as an array on the instantiated object, and are accessible
98
111
via ` $this->args ` .
@@ -105,23 +118,27 @@ Jobs can also have `setUp` and `tearDown` methods. If a `setUp` method
105
118
is defined, it will be called before the ` perform ` method is run.
106
119
The ` tearDown ` method if defined, will be called after the job finishes.
107
120
108
- class My_Job
109
- {
110
- public function setUp()
111
- {
112
- // ... Set up environment for this job
113
- }
114
121
115
- public function perform()
116
- {
117
- // .. Run job
118
- }
122
+ ``` php
119
123
120
- public function tearDown()
121
- {
122
- // ... Remove environment for this job
123
- }
124
- }
124
+ class My_Job
125
+ {
126
+ public function setUp()
127
+ {
128
+ // ... Set up environment for this job
129
+ }
130
+
131
+ public function perform()
132
+ {
133
+ // .. Run job
134
+ }
135
+
136
+ public function tearDown()
137
+ {
138
+ // ... Remove environment for this job
139
+ }
140
+ }
141
+ ```
125
142
126
143
### Tracking Job Statuses ###
127
144
@@ -144,11 +161,11 @@ To fetch the status of a job:
144
161
Job statuses are defined as constants in the ` Resque_Job_Status ` class.
145
162
Valid statuses include:
146
163
147
- * ` Resque_Job_Status::STATUS_WAITING ` - Job is still queued
148
- * ` Resque_Job_Status::STATUS_RUNNING ` - Job is currently running
149
- * ` Resque_Job_Status::STATUS_FAILED ` - Job has failed
150
- * ` Resque_Job_Status::STATUS_COMPLETE ` - Job is complete
151
- * ` false ` - Failed to fetch the status - is the token valid?
164
+ * `Resque_Job_Status::STATUS_WAITING` - Job is still queued
165
+ * `Resque_Job_Status::STATUS_RUNNING` - Job is currently running
166
+ * `Resque_Job_Status::STATUS_FAILED` - Job has failed
167
+ * `Resque_Job_Status::STATUS_COMPLETE` - Job is complete
168
+ * `false` - Failed to fetch the status - is the token valid?
152
169
153
170
Statuses are available for up to 24 hours after a job has completed
154
171
or failed, and are then automatically expired. A status can also
@@ -177,7 +194,9 @@ It's your responsibility to tell the worker which file to include to get
177
194
your application underway. You do so by setting the ` APP_INCLUDE ` environment
178
195
variable:
179
196
197
+ ``` sh
180
198
$ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque
199
+ ```
181
200
182
201
* Pro tip: Using Composer? More than likely, you don't need to worry about
183
202
` APP_INCLUDE ` , because hopefully Composer is responsible for autoloading
@@ -192,8 +211,10 @@ The port supports the same environment variables for logging to STDOUT.
192
211
Setting ` VERBOSE ` will print basic debugging information and ` VVERBOSE `
193
212
will print detailed information.
194
213
214
+ ``` sh
195
215
$ VERBOSE QUEUE=file_serve bin/resque
196
216
$ VVERBOSE QUEUE=file_serve bin/resque
217
+ ```
197
218
198
219
### Priorities and Queue Lists ###
199
220
@@ -204,7 +225,9 @@ checked in.
204
225
205
226
As per the original example:
206
227
228
+ ``` sh
207
229
$ QUEUE=file_serve,warm_cache bin/resque
230
+ ```
208
231
209
232
The ` file_serve ` queue will always be checked for new jobs on each
210
233
iteration before the ` warm_cache ` queue is checked.
@@ -214,21 +237,27 @@ iteration before the `warm_cache` queue is checked.
214
237
All queues are supported in the same manner and processed in alphabetical
215
238
order:
216
239
240
+ ``` sh
217
241
$ QUEUE=* bin/resque
242
+ ```
218
243
219
244
### Running Multiple Workers ###
220
245
221
246
Multiple workers ca be launched and automatically worked by supplying
222
247
the ` COUNT ` environment variable:
223
248
224
- $ COUNT=5 bin/resque
249
+ ``` sh
250
+ $ COUNT=5 bin/resque
251
+ ```
225
252
226
253
### Custom prefix ###
227
254
228
255
When you have multiple apps using the same Redis database it is better to
229
256
use a custom prefix to separate the Resque data:
230
257
231
- $ PREFIX=my-app-name bin/resque
258
+ ``` sh
259
+ $ PREFIX=my-app-name bin/resque
260
+ ```
232
261
233
262
### Forking ###
234
263
@@ -245,11 +274,11 @@ the job.
245
274
Signals also work on supported platforms exactly as in the Ruby
246
275
version of Resque:
247
276
248
- * ` QUIT ` - Wait for child to finish processing then exit
249
- * ` TERM ` / ` INT ` - Immediately kill child then exit
250
- * ` USR1 ` - Immediately kill child but don't exit
251
- * ` USR2 ` - Pause worker, no new jobs will be processed
252
- * ` CONT ` - Resume worker.
277
+ * `QUIT` - Wait for child to finish processing then exit
278
+ * `TERM` / `INT` - Immediately kill child then exit
279
+ * `USR1` - Immediately kill child but don't exit
280
+ * `USR2` - Pause worker, no new jobs will be processed
281
+ * `CONT` - Resume worker.
253
282
254
283
### Process Titles/Statuses ###
255
284
@@ -274,14 +303,16 @@ You listen in on events (as listed below) by registering with `Resque_Event`
274
303
and supplying a callback that you would like triggered when the event is
275
304
raised:
276
305
306
+ ``` sh
277
307
Resque_Event::listen(' eventName' , [callback]);
308
+ ```
278
309
279
310
` [callback] ` may be anything in PHP that is callable by ` call_user_func_array ` :
280
311
281
- * A string with the name of a function
282
- * An array containing an object and method to call
283
- * An array containing an object and a static method to call
284
- * A closure (PHP 5.3)
312
+ * A string with the name of a function
313
+ * An array containing an object and method to call
314
+ * An array containing an object and a static method to call
315
+ * A closure (PHP 5.3)
285
316
286
317
Events may pass arguments (documented below), so your callback should accept
287
318
these arguments.
@@ -358,24 +389,24 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments
358
389
359
390
## Contributors ##
360
391
361
- * chrisboulton
362
- * thedotedge
363
- * hobodave
364
- * scraton
365
- * KevBurnsJr
366
- * jmathai
367
- * dceballos
368
- * patrickbajao
369
- * andrewjshults
370
- * warezthebeef
371
- * d11wtq
372
- * hlegius
373
- * salimane
374
- * humancopy
375
- * pedroarnal
376
- * chaitanyakuber
377
- * maetl
378
- * Matt Heath
379
- * jjfrey
380
- * scragg0x
381
- * ruudk
392
+ * chrisboulton
393
+ * thedotedge
394
+ * hobodave
395
+ * scraton
396
+ * KevBurnsJr
397
+ * jmathai
398
+ * dceballos
399
+ * patrickbajao
400
+ * andrewjshults
401
+ * warezthebeef
402
+ * d11wtq
403
+ * hlegius
404
+ * salimane
405
+ * humancopy
406
+ * pedroarnal
407
+ * chaitanyakuber
408
+ * maetl
409
+ * Matt Heath
410
+ * jjfrey
411
+ * scragg0x
412
+ * ruudk
0 commit comments