Skip to content

Commit b5ce47a

Browse files
committed
Merge pull request #118 from rajibahmed/master
Add github flavoured syntax highlights on README
2 parents a1cfc29 + 14989b0 commit b5ce47a

File tree

1 file changed

+82
-53
lines changed

1 file changed

+82
-53
lines changed

README.md

Lines changed: 82 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -51,47 +51,55 @@ If you're not familiar with Composer, please see <http://getcomposer.org/>.
5151

5252
1. Add php-resque to your application's composer.json.
5353

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+
```
6163

6264
2. Run `composer install`.
6365

6466
3. If you haven't already, add the Composer autoload to your project's
6567
initialization file. (example)
6668

67-
require 'vendor/autoload.php';
69+
```sh
70+
require 'vendor/autoload.php';
71+
```
6872

6973
## Jobs ##
7074

7175
### Queueing Jobs ###
7276

7377
Jobs are queued as follows:
7478

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');
7782

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+
```
8288

8389
### Defining Jobs ###
8490

8591
Each job should be in it's own class, and include a `perform` method.
8692

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+
```
95103

96104
When the job is run, the class will be instantiated and any arguments
97105
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
105113
is defined, it will be called before the `perform` method is run.
106114
The `tearDown` method if defined, will be called after the job finishes.
107115

108-
class My_Job
109-
{
110-
public function setUp()
111-
{
112-
// ... Set up environment for this job
113-
}
114116

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+
}
119124

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+
```
125136

126137
### Tracking Job Statuses ###
127138

@@ -133,13 +144,17 @@ To track the status of a job, pass `true` as the fourth argument to
133144
`Resque::enqueue`. A token used for tracking the job status will be
134145
returned:
135146

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+
```
138151

139152
To fetch the status of a job:
140153

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+
```
143158

144159
Job statuses are defined as constants in the `Resque_Job_Status` class.
145160
Valid statuses include:
@@ -170,14 +185,16 @@ not having a single environment such as with Ruby, the PHP port makes
170185
*no* assumptions about your setup.
171186

172187
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+
```
176191
It's your responsibility to tell the worker which file to include to get
177192
your application underway. You do so by setting the `APP_INCLUDE` environment
178193
variable:
179194

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+
```
181198

182199
*Pro tip: Using Composer? More than likely, you don't need to worry about
183200
`APP_INCLUDE`, because hopefully Composer is responsible for autoloading
@@ -192,8 +209,10 @@ The port supports the same environment variables for logging to STDOUT.
192209
Setting `VERBOSE` will print basic debugging information and `VVERBOSE`
193210
will print detailed information.
194211

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+
```
197216

198217
### Priorities and Queue Lists ###
199218

@@ -204,7 +223,9 @@ checked in.
204223

205224
As per the original example:
206225

207-
$ QUEUE=file_serve,warm_cache bin/resque
226+
```sh
227+
$ QUEUE=file_serve,warm_cache bin/resque
228+
```
208229

209230
The `file_serve` queue will always be checked for new jobs on each
210231
iteration before the `warm_cache` queue is checked.
@@ -214,21 +235,27 @@ iteration before the `warm_cache` queue is checked.
214235
All queues are supported in the same manner and processed in alphabetical
215236
order:
216237

217-
$ QUEUE=* bin/resque
238+
```sh
239+
$ QUEUE=* bin/resque
240+
```
218241

219242
### Running Multiple Workers ###
220243

221244
Multiple workers ca be launched and automatically worked by supplying
222245
the `COUNT` environment variable:
223246

224-
$ COUNT=5 bin/resque
247+
```sh
248+
$ COUNT=5 bin/resque
249+
```
225250

226251
### Custom prefix ###
227252

228253
When you have multiple apps using the same Redis database it is better to
229254
use a custom prefix to separate the Resque data:
230255

231-
$ PREFIX=my-app-name bin/resque
256+
```sh
257+
$ PREFIX=my-app-name bin/resque
258+
```
232259

233260
### Forking ###
234261

@@ -274,7 +301,9 @@ You listen in on events (as listed below) by registering with `Resque_Event`
274301
and supplying a callback that you would like triggered when the event is
275302
raised:
276303

277-
Resque_Event::listen('eventName', [callback]);
304+
```sh
305+
Resque_Event::listen('eventName', [callback]);
306+
```
278307

279308
`[callback]` may be anything in PHP that is callable by `call_user_func_array`:
280309

@@ -358,7 +387,7 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments
358387

359388
## Contributors ##
360389

361-
* chrisboulton
390+
* chrisboulton
362391
* thedotedge
363392
* hobodave
364393
* scraton

0 commit comments

Comments
 (0)