@@ -51,47 +51,55 @@ 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
- {
55
- ...
56
- "require": {
57
- "chrisboulton/php-resque": "1.2.x"
58
- },
59
- ...
60
- }
54
+ ``` json
55
+ {
56
+ //...
57
+ "require" : {
58
+ "chrisboulton/php-resque" : " 1.2.x"
59
+ },
60
+ // ...
61
+ }
62
+ ```
61
63
62
64
2 . Run ` composer install ` .
63
65
64
66
3 . If you haven't already, add the Composer autoload to your project's
65
67
initialization file. (example)
66
68
67
- require 'vendor/autoload.php';
69
+ ``` sh
70
+ require ' vendor/autoload.php' ;
71
+ ```
68
72
69
73
## Jobs ##
70
74
71
75
### Queueing Jobs ###
72
76
73
77
Jobs are queued as follows:
74
78
75
- // Required if redis is located elsewhere
76
- Resque::setBackend('localhost:6379');
79
+ ``` php
80
+ // Required if redis is located elsewhere
81
+ Resque::setBackend('localhost:6379');
77
82
78
- $args = array(
79
- 'name' => 'Chris'
80
- );
81
- Resque::enqueue('default', 'My_Job', $args);
83
+ $args = array(
84
+ 'name' => 'Chris'
85
+ );
86
+ Resque::enqueue('default', 'My_Job', $args);
87
+ ```
82
88
83
89
### Defining Jobs ###
84
90
85
91
Each job should be in it's own class, and include a ` perform ` method.
86
92
87
- class My_Job
88
- {
89
- public function perform()
90
- {
91
- // Work work work
92
- echo $this->args['name'];
93
- }
94
- }
93
+ ``` php
94
+ class My_Job
95
+ {
96
+ public function perform()
97
+ {
98
+ // Work work work
99
+ echo $this->args['name'];
100
+ }
101
+ }
102
+ ```
95
103
96
104
When the job is run, the class will be instantiated and any arguments
97
105
will be set as an array on the instantiated object, and are accessible
@@ -105,23 +113,26 @@ Jobs can also have `setUp` and `tearDown` methods. If a `setUp` method
105
113
is defined, it will be called before the ` perform ` method is run.
106
114
The ` tearDown ` method if defined, will be called after the job finishes.
107
115
108
- class My_Job
109
- {
110
- public function setUp()
111
- {
112
- // ... Set up environment for this job
113
- }
114
116
115
- public function perform()
116
- {
117
- // .. Run job
118
- }
117
+ ``` php
118
+ class My_Job
119
+ {
120
+ public function setUp()
121
+ {
122
+ // ... Set up environment for this job
123
+ }
119
124
120
- public function tearDown()
121
- {
122
- // ... Remove environment for this job
123
- }
124
- }
125
+ public function perform()
126
+ {
127
+ // .. Run job
128
+ }
129
+
130
+ public function tearDown()
131
+ {
132
+ // ... Remove environment for this job
133
+ }
134
+ }
135
+ ```
125
136
126
137
### Tracking Job Statuses ###
127
138
@@ -133,13 +144,17 @@ To track the status of a job, pass `true` as the fourth argument to
133
144
` Resque::enqueue ` . A token used for tracking the job status will be
134
145
returned:
135
146
136
- $token = Resque::enqueue('default', 'My_Job', $args, true);
137
- echo $token;
147
+ ``` php
148
+ $token = Resque::enqueue('default', 'My_Job', $args, true);
149
+ echo $token;
150
+ ```
138
151
139
152
To fetch the status of a job:
140
153
141
- $status = new Resque_Job_Status($token);
142
- echo $status->get(); // Outputs the status
154
+ ``` php
155
+ $status = new Resque_Job_Status($token);
156
+ echo $status->get(); // Outputs the status
157
+ ```
143
158
144
159
Job statuses are defined as constants in the ` Resque_Job_Status ` class.
145
160
Valid statuses include:
@@ -170,14 +185,16 @@ not having a single environment such as with Ruby, the PHP port makes
170
185
* no* assumptions about your setup.
171
186
172
187
To start a worker, it's very similar to the Ruby version:
173
-
174
- $ QUEUE=file_serve php bin/resque
175
-
188
+ ``` sh
189
+ $ QUEUE=file_serve php bin/resque
190
+ ```
176
191
It's your responsibility to tell the worker which file to include to get
177
192
your application underway. You do so by setting the ` APP_INCLUDE ` environment
178
193
variable:
179
194
180
- $ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque
195
+ ``` sh
196
+ $ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque
197
+ ```
181
198
182
199
* Pro tip: Using Composer? More than likely, you don't need to worry about
183
200
` APP_INCLUDE ` , because hopefully Composer is responsible for autoloading
@@ -192,8 +209,10 @@ The port supports the same environment variables for logging to STDOUT.
192
209
Setting ` VERBOSE ` will print basic debugging information and ` VVERBOSE `
193
210
will print detailed information.
194
211
195
- $ VERBOSE QUEUE=file_serve bin/resque
196
- $ VVERBOSE QUEUE=file_serve bin/resque
212
+ ``` sh
213
+ $ VERBOSE QUEUE=file_serve bin/resque
214
+ $ VVERBOSE QUEUE=file_serve bin/resque
215
+ ```
197
216
198
217
### Priorities and Queue Lists ###
199
218
@@ -204,7 +223,9 @@ checked in.
204
223
205
224
As per the original example:
206
225
207
- $ QUEUE=file_serve,warm_cache bin/resque
226
+ ``` sh
227
+ $ QUEUE=file_serve,warm_cache bin/resque
228
+ ```
208
229
209
230
The ` file_serve ` queue will always be checked for new jobs on each
210
231
iteration before the ` warm_cache ` queue is checked.
@@ -214,21 +235,27 @@ iteration before the `warm_cache` queue is checked.
214
235
All queues are supported in the same manner and processed in alphabetical
215
236
order:
216
237
217
- $ QUEUE=* bin/resque
238
+ ``` sh
239
+ $ QUEUE=* bin/resque
240
+ ```
218
241
219
242
### Running Multiple Workers ###
220
243
221
244
Multiple workers ca be launched and automatically worked by supplying
222
245
the ` COUNT ` environment variable:
223
246
224
- $ COUNT=5 bin/resque
247
+ ``` sh
248
+ $ COUNT=5 bin/resque
249
+ ```
225
250
226
251
### Custom prefix ###
227
252
228
253
When you have multiple apps using the same Redis database it is better to
229
254
use a custom prefix to separate the Resque data:
230
255
231
- $ PREFIX=my-app-name bin/resque
256
+ ``` sh
257
+ $ PREFIX=my-app-name bin/resque
258
+ ```
232
259
233
260
### Forking ###
234
261
@@ -274,7 +301,9 @@ You listen in on events (as listed below) by registering with `Resque_Event`
274
301
and supplying a callback that you would like triggered when the event is
275
302
raised:
276
303
277
- Resque_Event::listen('eventName', [callback]);
304
+ ``` sh
305
+ Resque_Event::listen(' eventName' , [callback]);
306
+ ```
278
307
279
308
` [callback] ` may be anything in PHP that is callable by ` call_user_func_array ` :
280
309
@@ -358,7 +387,7 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments
358
387
359
388
## Contributors ##
360
389
361
- * chrisboulton
390
+ * chrisboulton
362
391
* thedotedge
363
392
* hobodave
364
393
* scraton
0 commit comments