From 271b5849573195d5f6be359038c3d2696b109b1a Mon Sep 17 00:00:00 2001 From: Rajib Ahmed Date: Thu, 18 Jul 2013 09:53:30 +0200 Subject: [PATCH 1/3] Add github style syntax highlights on README file. --- README.md | 135 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index fc1047a..5feb344 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ If you're not familiar with Composer, please see . 1. Add php-resque to your application's composer.json. +```json + { ... "require": { @@ -58,13 +60,16 @@ If you're not familiar with Composer, please see . }, ... } +``` 2. Run `composer install`. 3. If you haven't already, add the Composer autoload to your project's initialization file. (example) +```sh require 'vendor/autoload.php'; +``` ## Jobs ## @@ -72,6 +77,8 @@ If you're not familiar with Composer, please see . Jobs are queued as follows: +```php + // Required if redis is located elsewhere Resque::setBackend('localhost:6379'); @@ -80,10 +87,14 @@ Jobs are queued as follows: ); Resque::enqueue('default', 'My_Job', $args); +``` + ### Defining Jobs ### Each job should be in it's own class, and include a `perform` method. +```php + class My_Job { public function perform() @@ -93,6 +104,8 @@ Each job should be in it's own class, and include a `perform` method. } } +``` + When the job is run, the class will be instantiated and any arguments will be set as an array on the instantiated object, and are accessible via `$this->args`. @@ -105,23 +118,27 @@ Jobs can also have `setUp` and `tearDown` methods. If a `setUp` method is defined, it will be called before the `perform` method is run. The `tearDown` method if defined, will be called after the job finishes. - class My_Job - { - public function setUp() - { - // ... Set up environment for this job - } - public function perform() - { - // .. Run job - } +```php - public function tearDown() - { - // ... Remove environment for this job - } - } + class My_Job + { + public function setUp() + { + // ... Set up environment for this job + } + + public function perform() + { + // .. Run job + } + + public function tearDown() + { + // ... Remove environment for this job + } + } +``` ### Tracking Job Statuses ### @@ -144,11 +161,11 @@ To fetch the status of a job: Job statuses are defined as constants in the `Resque_Job_Status` class. Valid statuses include: -* `Resque_Job_Status::STATUS_WAITING` - Job is still queued -* `Resque_Job_Status::STATUS_RUNNING` - Job is currently running -* `Resque_Job_Status::STATUS_FAILED` - Job has failed -* `Resque_Job_Status::STATUS_COMPLETE` - Job is complete -* `false` - Failed to fetch the status - is the token valid? + * `Resque_Job_Status::STATUS_WAITING` - Job is still queued + * `Resque_Job_Status::STATUS_RUNNING` - Job is currently running + * `Resque_Job_Status::STATUS_FAILED` - Job has failed + * `Resque_Job_Status::STATUS_COMPLETE` - Job is complete + * `false` - Failed to fetch the status - is the token valid? Statuses are available for up to 24 hours after a job has completed 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 your application underway. You do so by setting the `APP_INCLUDE` environment variable: +```sh $ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque +``` *Pro tip: Using Composer? More than likely, you don't need to worry about `APP_INCLUDE`, because hopefully Composer is responsible for autoloading @@ -192,8 +211,10 @@ The port supports the same environment variables for logging to STDOUT. Setting `VERBOSE` will print basic debugging information and `VVERBOSE` will print detailed information. +```sh $ VERBOSE QUEUE=file_serve bin/resque $ VVERBOSE QUEUE=file_serve bin/resque +``` ### Priorities and Queue Lists ### @@ -204,7 +225,9 @@ checked in. As per the original example: +```sh $ QUEUE=file_serve,warm_cache bin/resque +``` The `file_serve` queue will always be checked for new jobs on each iteration before the `warm_cache` queue is checked. @@ -214,21 +237,27 @@ iteration before the `warm_cache` queue is checked. All queues are supported in the same manner and processed in alphabetical order: +```sh $ QUEUE=* bin/resque +``` ### Running Multiple Workers ### Multiple workers ca be launched and automatically worked by supplying the `COUNT` environment variable: - $ COUNT=5 bin/resque +```sh + $ COUNT=5 bin/resque +``` ### Custom prefix ### When you have multiple apps using the same Redis database it is better to use a custom prefix to separate the Resque data: - $ PREFIX=my-app-name bin/resque +```sh + $ PREFIX=my-app-name bin/resque +``` ### Forking ### @@ -245,11 +274,11 @@ the job. Signals also work on supported platforms exactly as in the Ruby version of Resque: -* `QUIT` - Wait for child to finish processing then exit -* `TERM` / `INT` - Immediately kill child then exit -* `USR1` - Immediately kill child but don't exit -* `USR2` - Pause worker, no new jobs will be processed -* `CONT` - Resume worker. + * `QUIT` - Wait for child to finish processing then exit + * `TERM` / `INT` - Immediately kill child then exit + * `USR1` - Immediately kill child but don't exit + * `USR2` - Pause worker, no new jobs will be processed + * `CONT` - Resume worker. ### Process Titles/Statuses ### @@ -274,14 +303,16 @@ You listen in on events (as listed below) by registering with `Resque_Event` and supplying a callback that you would like triggered when the event is raised: +```sh Resque_Event::listen('eventName', [callback]); +``` `[callback]` may be anything in PHP that is callable by `call_user_func_array`: -* A string with the name of a function -* An array containing an object and method to call -* An array containing an object and a static method to call -* A closure (PHP 5.3) + * A string with the name of a function + * An array containing an object and method to call + * An array containing an object and a static method to call + * A closure (PHP 5.3) Events may pass arguments (documented below), so your callback should accept these arguments. @@ -358,24 +389,24 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments ## Contributors ## -* chrisboulton -* thedotedge -* hobodave -* scraton -* KevBurnsJr -* jmathai -* dceballos -* patrickbajao -* andrewjshults -* warezthebeef -* d11wtq -* hlegius -* salimane -* humancopy -* pedroarnal -* chaitanyakuber -* maetl -* Matt Heath -* jjfrey -* scragg0x -* ruudk + * chrisboulton + * thedotedge + * hobodave + * scraton + * KevBurnsJr + * jmathai + * dceballos + * patrickbajao + * andrewjshults + * warezthebeef + * d11wtq + * hlegius + * salimane + * humancopy + * pedroarnal + * chaitanyakuber + * maetl + * Matt Heath + * jjfrey + * scragg0x + * ruudk From 2d4458fbed8ef43c60ff8338e489dfc1a9413669 Mon Sep 17 00:00:00 2001 From: Rajib Ahmed Date: Thu, 18 Jul 2013 09:57:53 +0200 Subject: [PATCH 2/3] Add fix to syntax highlights. --- README.md | 74 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 5feb344..ae9a355 100644 --- a/README.md +++ b/README.md @@ -150,22 +150,26 @@ To track the status of a job, pass `true` as the fourth argument to `Resque::enqueue`. A token used for tracking the job status will be returned: +```php $token = Resque::enqueue('default', 'My_Job', $args, true); echo $token; +``` To fetch the status of a job: +```php $status = new Resque_Job_Status($token); echo $status->get(); // Outputs the status +``` Job statuses are defined as constants in the `Resque_Job_Status` class. Valid statuses include: - * `Resque_Job_Status::STATUS_WAITING` - Job is still queued - * `Resque_Job_Status::STATUS_RUNNING` - Job is currently running - * `Resque_Job_Status::STATUS_FAILED` - Job has failed - * `Resque_Job_Status::STATUS_COMPLETE` - Job is complete - * `false` - Failed to fetch the status - is the token valid? +* `Resque_Job_Status::STATUS_WAITING` - Job is still queued +* `Resque_Job_Status::STATUS_RUNNING` - Job is currently running +* `Resque_Job_Status::STATUS_FAILED` - Job has failed +* `Resque_Job_Status::STATUS_COMPLETE` - Job is complete +* `false` - Failed to fetch the status - is the token valid? Statuses are available for up to 24 hours after a job has completed or failed, and are then automatically expired. A status can also @@ -274,11 +278,11 @@ the job. Signals also work on supported platforms exactly as in the Ruby version of Resque: - * `QUIT` - Wait for child to finish processing then exit - * `TERM` / `INT` - Immediately kill child then exit - * `USR1` - Immediately kill child but don't exit - * `USR2` - Pause worker, no new jobs will be processed - * `CONT` - Resume worker. +* `QUIT` - Wait for child to finish processing then exit +* `TERM` / `INT` - Immediately kill child then exit +* `USR1` - Immediately kill child but don't exit +* `USR2` - Pause worker, no new jobs will be processed +* `CONT` - Resume worker. ### Process Titles/Statuses ### @@ -309,10 +313,10 @@ raised: `[callback]` may be anything in PHP that is callable by `call_user_func_array`: - * A string with the name of a function - * An array containing an object and method to call - * An array containing an object and a static method to call - * A closure (PHP 5.3) +* A string with the name of a function +* An array containing an object and method to call +* An array containing an object and a static method to call +* A closure (PHP 5.3) Events may pass arguments (documented below), so your callback should accept these arguments. @@ -389,24 +393,24 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments ## Contributors ## - * chrisboulton - * thedotedge - * hobodave - * scraton - * KevBurnsJr - * jmathai - * dceballos - * patrickbajao - * andrewjshults - * warezthebeef - * d11wtq - * hlegius - * salimane - * humancopy - * pedroarnal - * chaitanyakuber - * maetl - * Matt Heath - * jjfrey - * scragg0x - * ruudk +* chrisboulton +* thedotedge +* hobodave +* scraton +* KevBurnsJr +* jmathai +* dceballos +* patrickbajao +* andrewjshults +* warezthebeef +* d11wtq +* hlegius +* salimane +* humancopy +* pedroarnal +* chaitanyakuber +* maetl +* Matt Heath +* jjfrey +* scragg0x +* ruudk From 14989b0e9e380ccfd40e799ac0e291fe33fe38ff Mon Sep 17 00:00:00 2001 From: Rajib Ahmed Date: Thu, 18 Jul 2013 11:51:02 +0200 Subject: [PATCH 3/3] Remove spaces from README code samples. --- README.md | 110 ++++++++++++++++++++++++++---------------------------- 1 file changed, 52 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index ae9a355..8b8bb53 100644 --- a/README.md +++ b/README.md @@ -52,14 +52,13 @@ If you're not familiar with Composer, please see . 1. Add php-resque to your application's composer.json. ```json - - { - ... - "require": { - "chrisboulton/php-resque": "1.2.x" - }, - ... - } +{ + //... + "require": { + "chrisboulton/php-resque": "1.2.x" + }, + // ... +} ``` 2. Run `composer install`. @@ -68,7 +67,7 @@ If you're not familiar with Composer, please see . initialization file. (example) ```sh - require 'vendor/autoload.php'; +require 'vendor/autoload.php'; ``` ## Jobs ## @@ -78,15 +77,13 @@ If you're not familiar with Composer, please see . Jobs are queued as follows: ```php +// Required if redis is located elsewhere +Resque::setBackend('localhost:6379'); - // Required if redis is located elsewhere - Resque::setBackend('localhost:6379'); - - $args = array( - 'name' => 'Chris' - ); - Resque::enqueue('default', 'My_Job', $args); - +$args = array( + 'name' => 'Chris' + ); +Resque::enqueue('default', 'My_Job', $args); ``` ### Defining Jobs ### @@ -94,16 +91,14 @@ Jobs are queued as follows: Each job should be in it's own class, and include a `perform` method. ```php - - class My_Job - { - public function perform() - { - // Work work work - echo $this->args['name']; - } - } - +class My_Job +{ + public function perform() + { + // Work work work + echo $this->args['name']; + } +} ``` When the job is run, the class will be instantiated and any arguments @@ -120,24 +115,23 @@ The `tearDown` method if defined, will be called after the job finishes. ```php - - class My_Job +class My_Job +{ + public function setUp() { - public function setUp() - { - // ... Set up environment for this job - } - - public function perform() - { - // .. Run job - } - - public function tearDown() - { - // ... Remove environment for this job - } + // ... Set up environment for this job } + + public function perform() + { + // .. Run job + } + + public function tearDown() + { + // ... Remove environment for this job + } +} ``` ### Tracking Job Statuses ### @@ -151,15 +145,15 @@ To track the status of a job, pass `true` as the fourth argument to returned: ```php - $token = Resque::enqueue('default', 'My_Job', $args, true); - echo $token; +$token = Resque::enqueue('default', 'My_Job', $args, true); +echo $token; ``` To fetch the status of a job: ```php - $status = new Resque_Job_Status($token); - echo $status->get(); // Outputs the status +$status = new Resque_Job_Status($token); +echo $status->get(); // Outputs the status ``` Job statuses are defined as constants in the `Resque_Job_Status` class. @@ -191,15 +185,15 @@ not having a single environment such as with Ruby, the PHP port makes *no* assumptions about your setup. To start a worker, it's very similar to the Ruby version: - - $ QUEUE=file_serve php bin/resque - +```sh +$ QUEUE=file_serve php bin/resque +``` It's your responsibility to tell the worker which file to include to get your application underway. You do so by setting the `APP_INCLUDE` environment variable: ```sh - $ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque +$ QUEUE=file_serve APP_INCLUDE=../application/init.php php bin/resque ``` *Pro tip: Using Composer? More than likely, you don't need to worry about @@ -216,8 +210,8 @@ Setting `VERBOSE` will print basic debugging information and `VVERBOSE` will print detailed information. ```sh - $ VERBOSE QUEUE=file_serve bin/resque - $ VVERBOSE QUEUE=file_serve bin/resque +$ VERBOSE QUEUE=file_serve bin/resque +$ VVERBOSE QUEUE=file_serve bin/resque ``` ### Priorities and Queue Lists ### @@ -230,7 +224,7 @@ checked in. As per the original example: ```sh - $ QUEUE=file_serve,warm_cache bin/resque +$ QUEUE=file_serve,warm_cache bin/resque ``` The `file_serve` queue will always be checked for new jobs on each @@ -242,7 +236,7 @@ All queues are supported in the same manner and processed in alphabetical order: ```sh - $ QUEUE=* bin/resque +$ QUEUE=* bin/resque ``` ### Running Multiple Workers ### @@ -251,7 +245,7 @@ Multiple workers ca be launched and automatically worked by supplying the `COUNT` environment variable: ```sh - $ COUNT=5 bin/resque +$ COUNT=5 bin/resque ``` ### Custom prefix ### @@ -260,7 +254,7 @@ When you have multiple apps using the same Redis database it is better to use a custom prefix to separate the Resque data: ```sh - $ PREFIX=my-app-name bin/resque +$ PREFIX=my-app-name bin/resque ``` ### Forking ### @@ -308,7 +302,7 @@ and supplying a callback that you would like triggered when the event is raised: ```sh - Resque_Event::listen('eventName', [callback]); +Resque_Event::listen('eventName', [callback]); ``` `[callback]` may be anything in PHP that is callable by `call_user_func_array`: