README.markdown in tennis-jobs-0.1.0 vs README.markdown in tennis-jobs-0.2.0
- old
+ new
@@ -1,11 +1,12 @@
This small library is intended to help creating asynchronous jobs
using Ruby and RabbitMQ via the Sneakers gem.
-<a href="https://travis-ci.org/nicoolas25/tennis"><img src="https://travis-ci.org/nicoolas25/tennis.svg?branch=master" /></a>
-<a href="https://codeclimate.com/github/nicoolas25/tennis"><img src="https://codeclimate.com/github/nicoolas25/tennis/badges/gpa.svg" /></a>
-<a href="https://codeclimate.com/github/nicoolas25/tennis/coverage"><img src="https://codeclimate.com/github/nicoolas25/tennis/badges/coverage.svg" /></a>
+<a target="_blank" href="https://travis-ci.org/nicoolas25/tennis"><img src="https://travis-ci.org/nicoolas25/tennis.svg?branch=master" /></a>
+<a target="_blank" href="https://codeclimate.com/github/nicoolas25/tennis"><img src="https://codeclimate.com/github/nicoolas25/tennis/badges/gpa.svg" /></a>
+<a target="_blank" href="https://codeclimate.com/github/nicoolas25/tennis/coverage"><img src="https://codeclimate.com/github/nicoolas25/tennis/badges/coverage.svg" /></a>
+<a target="_blank" href="https://rubygems.org/gems/tennis-jobs"><img src="https://badge.fury.io/rb/tennis-jobs.svg" /></a>
## Features
- Hooks: `.before(symbol, &block)`
- Serializers: `.serialize(loader:)`
@@ -13,15 +14,73 @@
**Extra**
- A `GenericSerializer` handling classes and ActiveRecord objects
+## Configuration
+
+The background job require a group of processes to handle the tasks you want to
+do asynchronously. Tennis uses YAML configuration file in order to launch thoses
+processes.
+
+``` yaml
+# tennis.conf.yml
+group1:
+ exchange: "default"
+ workers: 1
+ classes:
+ - "Scope::MyClass"
+ - "Scope::Model"
+group2:
+ exchange: "important"
+ workers: 10
+ classes:
+ - "Only::ImportantWorker"
+```
+
+Here we see two groups of worker. Each group can be launch with the `tennis`
+command:
+
+ $ bundle exec tennis group1
+
+The `workers` options is directly given to sneakers, it will determine the
+number of subprocesses that will handle the messages, the level of parallelism.
+
+The classes are the classes that will receive your `execute` or `defer` calls
+but we'll see that later...
+
+Also it is possible to add options directly in your workers:
+
+``` ruby
+module WorkerHelpers
+ BeforeFork = -> { ActiveRecord::Base.connection_pool.disconnect! rescue nil }
+ AfterFork = -> { ActiveRecord::Base.establish_connection }
+end
+
+class MyClass
+ include GenericWorker
+
+ set_option :before_fork, WorkerHelpers::BeforeFork
+ set_option :after_fork, WorkerHelpers::AfterFork
+ set_option :handler, Sneakers::Handlers::MaxretryWithoutErrors
+
+ work do |message|
+ MyActiveRecordModel.create(message: message)
+ end
+end
+```
+
+In this example I use constants to store the Proc options. This is because
+having different options for the workers of a same group isn't possible. By
+using this constant, I can have another worker with those same options and put
+it in the same group.
+
## Examples
Those examples are what we wish to achieve.
The name of the queue is the name of the class by default and can be reset
-using sneakers' `.from_queue` method of the `YourClass::Worker`'s class.
+using sneakers' `YourClass.worker.from_queue` method.
### Hooks
``` ruby
class MyClass