Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from kamisama/fix-travis
Browse files Browse the repository at this point in the history
Connect with Travis and Coveralls
  • Loading branch information
wa0x6e committed Jun 20, 2013
2 parents 8db1d5f + 2ede45c commit e3e52b7
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 77 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src_dir: ./
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
composer.phar
composer.lock
vendor/
vendor/
/node_modules/
/build/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
##Changelog

###v1.2.0 (2013-06-xx)

* [new] Add `pause` and `resume` commands
* [new] Add `--debug` option
*

###v1.1.5 (2013-04-15)

* [fix] Fix composer
Expand Down
41 changes: 41 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
clean: {
coverage: ['build']
},
shell: {
coverage: {
command: 'phpunit tests'
} },
watch: {
scripts: {
files: ['tests/**/*.php', 'lib/*.php'],
tasks: ['test'],
options: {
nospawn: true
}
}
},
phpunit: {
classes: {
dir: 'tests/'
},
options: {
bin: 'phpunit',
bootstrap: 'tests/bootstrap.php',
colors: true,
noConfiguration: true
}
}
});

grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-phpunit');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');

grunt.registerTask('test', ['phpunit']);
grunt.registerTask('coverage', ['clean:coverage', 'shell:coverage']);
};
136 changes: 79 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,44 @@ If you don't know what is *resque* or *redis*, take a look at their official web
- Php-Resque : https://github.com/chrisboulton/php-resque/

This tool is intended to facilitate your life by making interfacing with php-resque more easier and more friendly.
You should already have some knowledge about php-resque, and have php-resque installed and running.
You should already have some knowledge about php-resque, and have php-resque installed and running.
I'll assume in this tutorial that you have sufficient knowledge to start a worker normally with php-resque.


##What is Fresque

Fresque is a command line tool.
But instead of starting a worker with

$ QUEUE=file_serve php resque.php

you do
Fresque is a command line tool to manage your php-resque workers

$ fresque start -q file_serve

It's more friendly, and provides more options, like `restart`, `stop`, etc …
Php-resque, and resque, by default doesn't provide an out-of-the-box way to stop your workers. You just kill the worker process. With Fresque, you'll enjoy stopping and restarting your workers at gogo.
# Starting a worker
$ QUEUE=file_serve php resque.php

# Starting a worker with fresque
$ fresque start -q file_serve

It's more friendly, and provides more options, like `restart`, `stop`, etc …
Php-resque, and resque, by default doesn't provide an out-of-the-box way to stop your workers. You just kill the worker process. With Fresque, you'll enjoy stopping and restarting your workers at gogo. No more system process handling!

##Installation

Clone the git repo

$ git clone git://github.com/kamisama/Fresque.git

`cd` to the Fresque folder you just cloned

$ cd the/fresque/folder/you/just/cloned

Then download Composer

$ curl -s https://getcomposer.org/installer | php

Finally, install dependencies

$ php composer.phar install

*NB: Official php-resque use redisent as redis api. If you want php-redis instead, take a look at my [fork](https://github.com/kamisama/php-resque).*

##Configuration

A fresque.ini file is provided to set your workers default parameters, and other options used by fresque, such as redis connection options.
A fresque.ini file is provided to set your workers default parameters, and other options used by fresque, such as redis connection options.
it's well documented, and you shouldn't have difficulties filling it.


Expand All @@ -60,25 +57,25 @@ it's well documented, and you shouldn't have difficulties filling it.
*Some examples are available at the end of this page.*

It's often wise to start by adding the fresque executable to your system path.
You then just call
You then just call

$ fresque <command>

Or if you didn't add it,

$ cd /path/to/the/resque/executable
$ ./fresque <command>





There's a bunch of interesting commands available :

* **start**

To start a new resque worker. Be default, it will use the default configuration defined in you fresque.ini for the queue name, the pooling frequency, and other various options. You can override all of them with an option flag. Available options :
To start a new resque worker. By default, it will use the default configuration defined in you fresque.ini for the queue name, the pooling frequency, and other various options. You can override all of them with an option flag. Available options :

> `-u` or `--user` : User running the php process. Should be the user running your php application, usually **www-data** for apache. Using a different user could lead to permissions problems in some cases.
>
>
> `-q` or `--queue` : A list of queues name, separated with a comma.
> `-i` or `--interval` : Pooling frequency. Number of seconds between each pooling.
Expand All @@ -93,11 +90,23 @@ For creating multiple queues with different options, just run `start` again.

* **stop**

To shutdown worker. Will wait for all jobs to finish, then shutdown the worker. If more than one worker is running, you'll have to choose the worker to stop from a worker menu.
To stop workers. Will wait for all jobs to finish, then stop the worker. If more than one worker is running, you'll have to choose the worker to stop from a worker menu.

> `-f` or `--force` : Force shutdown, without waiting for the jobs to finish. All jobs will fail.
> `-w` or `--all` : Stop all workers, skipping the worker menu.
* **pause**

To pause workers. Like with `stop`, a you'll be prompted with a worker list if more than one worker is available.

> `-w` or `--all` : Stop all workers, skipping the worker menu.
* **resume**

To resume paused workers. Again, you'll be prompted with a worker list if there is more than one paused worker.

> `-w` or `--all` : Stop all workers, skipping the worker menu.
* **restart**

To restart all the workers, keeping their settings.
Expand All @@ -117,9 +126,9 @@ Tail the workers' logs. If you have more than one log file, you'll have to choos
* **enqueue**

Add a job to a queue. Takes 3 arguments :
> **queuename** : Name of the queue you will enqueue this job to
> **jobclass** : Name of the class that will perform the job, and that your application autoloader will have to load.

> **queuename** : Name of the queue you will enqueue this job to
> **jobclass** : Name of the class that will perform the job, and that your application autoloader will have to load.
> **arguments** : comma separated list of arguments, passed to the job.
Will print the **Job ID** if the job is successfully enqueued.
Expand Down Expand Up @@ -157,27 +166,35 @@ Let's start another worker, named *activity*, with a pooling frequency of 1 seco
Then, I want another worker, that will work on the queues *default* and *activity* at the same time.

$ fresque start -q default,activity

Oh wait, I have another resque on another redis server. I want to log its activities in an other log file : remote.log

$ fresque start -s 192.168.1.26 -p 6390 -q myspecialqueue -l /path/to/remote.log

If you have your config file elsewhere, and your php-resque lib elsewhere also

$ fresque start -c /path/to/my-config.ini -b /path/to/my/custom/php-resque

To view stats of your workers (to know how many you have, processed/failed jobs count, uptime)

$ fresque stats

It should output something like that

Worker statistics
It should output something like that

-----------------
Resque statistics
-----------------

Jobs Stats
Processed Jobs : 18617
Failed Jobs : 319

Processed Jobs : 18,617
Failed Jobs : 319

Queues Stats
Queues count : 3
- default : 0 pending jobs
- myspecialqueue : 0 pending jobs
- activity : 0 pending jobs

Workers Stats
Active Workers : 6
Worker : KAMISAMA-MAC.local:33197:default
Expand Down Expand Up @@ -210,54 +227,56 @@ It should output something like that
- Uptime : less than a minute
- Processed Jobs : 0
- Failed Jobs : 0


Remember that you can use the global options (-s, -p etc …) with any command

$ fresque stop -c /path/to/my-config.ini -s 192.168.1.26
$ fresque stop -c /path/to/my-config.ini -s 192.168.1.26
Let's enqueue a job to the *activity* queue

$ fresque enqueue activity PageVisit 5 /index.php 158745693

php-resque will then run this job, by instantiating the class `PageVisit`, then calling the `perform()` method with the arguments `5`, `/index.php` and `158745693`.
In order to instantiate the PageVisit class, php-resque should know where to find it. That should be done with you application autoloader (`--include`)


Oh, and if you want to restart all your workers for whatever reasons

$ fresque restart

If you're finished, and want to stop all workers, just

$ fresque stop --all

It'll spout something like that

Shutting down Resque Worker complete
----------------
Stopping workers
----------------
Killing 6 workers ...
Killing 33197 … Done
Killing 33207 … Done
Killing 33215 … Done
Killing 33232 … Done
Killing 33233 … Done
Killing 33223 … Done

See notes if it says **There were no active workers to kill …** but you're sure there are some.

###Starting all the workers at once

We've just created 6 workers, calling `start` 5 times (remember, the second `start` create 2 workers with `-n 2`). But there's a way to start all of them with only one command, useful when you have a lot of workers that you have to start each time.

Just set all your workers settings in the config file in the [Queues] section (walkthrough available in the config file), then start all of them with

$ fresque load


##Notes

###You can test your config with `test`

A testing tool for testing your configuration file is provided, just call `test`.
A testing tool for testing your configuration file is provided, just call `test`.
This will test the minimum requirements to run fresque :

* Your redis hostname and port are not null
Expand All @@ -271,7 +290,7 @@ This will not test the content of your application autoloader, so if there's som
You can test more than the settings inside your config file, by passing options. An option will override the setting defined in the config

$ fresque test -s 195.168.1.26 -p 6890

This will test your config file, but with the specified redis hostname and port.

You can also test an other config file
Expand All @@ -280,15 +299,18 @@ You can also test an other config file

A test result will looks like

Testing configuration
---------------------
Testing configuration
---------------------
Testing configuration
Redis configuration .....OK
Redis server ............OK
Log File ................OK
PHPResque library .......OK
Application autoloader ..OK

Your settings seems ok

##Known issues

###`stop` command doesn't stop workers
Expand All @@ -298,26 +320,26 @@ This happens when you try to stop your workers, but it says **There were no acti
The only way to kill these 'stray' worker are to find their pid and kill them manually.

ps aux | grep resque.php

It will print a list a process. Find the PID of the stray workers and kill them

sudo kill YOUR_PID

##Notes

###Consult your logs

Logs tell you all you need to know about the issue of a job, and the current status of your php-resque workers. It tells you when a job is enqueued, when a job is about to being performed, and its issue (success/fail). It also display all php related errors that may occurs.
Logs tell you all you need to know about the issue of a job, and the current status of your php-resque workers. It tells you when a job is enqueued, when a job is about to being performed, and its issue (success/fail). It also display all php related errors that may occurs.
Check them frequently, as fresque doesn't capture those errors.


##Background

Fresque is a derivated works from my other plugin, [cake-resque](https://github.com/kamisama/Cake-Resque), a command line tool to manage php-resque, but inside cakephp console.
Very convenient, but limited to only cakephp framework. I wanted to release a tool that can work in any php environment.
Fresque is a derivated works from my other plugin, [cake-resque](https://github.com/kamisama/Cake-Resque), a command line tool to manage php-resque, but inside cakephp console.
Very convenient, but limited to only cakephp framework. I wanted to release a tool that can work in any php environment.

##Credits

* [PHP-Resque](https://github.com/chrisboulton/php-resque) is written by Chris Boulton
* [PHP-Resque](https://github.com/chrisboulton/php-resque) is written by Chris Boulton
* Based on [Resque](https://github.com/defunkt/resque) by defunkt
* Fresque by Wan Qi Chen (kamisama)
* Fresque by Wan Qi Chen (kamisama)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"zetacomponents/console-tools" : ">=1.6",
"zetacomponents/base" : ">=1.8",
"kamisama/resque-status": ">=0.0.1",
"kamisama/php-resque-ex": ">=1.2.5"
"kamisama/php-resque-ex": "dev-master"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master",
Expand Down
Loading

0 comments on commit e3e52b7

Please sign in to comment.