README.md in localjob-0.4.0 vs README.md in localjob-0.4.1
- old
+ new
@@ -1,11 +1,12 @@
# Localjob [![Build Status](https://travis-ci.org/Sirupsen/localjob.png?branch=master)](https://travis-ci.org/Sirupsen/localjob) [![Coverage Status](https://coveralls.io/repos/Sirupsen/localjob/badge.png?branch=master)](https://coveralls.io/r/Sirupsen/localjob?branch=master)
Localjob is a simple, self-contained background queue built on top of [System V
message queues][sysv] (SysV Message Queue => SysV MQ for short). Workers and the
app pushing to the queue must reside on the same machine. It's the sqlite of
-background queues. Here's a post about [how it works][blog].
+background queues. Here's a post about [how it works][blog]. You can run
+Localjob either as a seperate process, or as a thread in your app.
Localjob is for early-development situations where you don't need a
full-featured background queue, but just want to get started with something
simple that does not rely on any external services. The advantage of the SysV
queues is that your Rails app or worker can restart at any time, without loosing
@@ -14,11 +15,11 @@
Localjob works on Ruby >= 2.0.0 on Linux and OS X.
Add it to your Gemfile:
```ruby
-gem 'localjob', "~> 0.2"
+gem 'localjob'
```
## Usage
Localjobs have the following format:
@@ -65,10 +66,28 @@
BackgroundQueue << EmailJob.new(current_user.id, welcome_email)
```
### Managing workers
+There are two ways to spawn workers, either a thread inside the process emitting
+events, or as a separate process managed with the `localjob` command-line
+utility.
+
+#### Thread
+
+Spawn the worker thread in an initializer where you are initializing Localjob as
+well:
+
+```ruby
+BackgroundQueue = Localjob.new
+
+worker = Localjob::Worker.new(BackgroundQueue, logger: Rails.logger)
+worker.work(thread: true)
+```
+
+#### Process
+
Spawning workers can be done with `localjob`. Run `localjob work` to spawn a
single worker. It takes a few arguments. The most important being `--require`
which takes a path the worker will require before processing jobs. For Rails,
you can run `localjob work` without any arguments. `localjob(2)` has a few other
commands such as `list` to list all queues and `size` to list the size of all
@@ -111,8 +130,22 @@
@worker.process(job)
assert_equal 0, @localjob.size
end
```
+
+### Multiple queues
+
+If you wish to have multiple queues you can have multiple Localjob objects
+referencing different queues. A worker can only work off a single queue at a
+time, so you will have to spawn multiple thread or process workers. Example:
+
+```ruby
+MailQueue = Localjob.new(0xDEADC0DE)
+DefaultQueue = Localjob.new(0xDEADCAFE)
+```
+
+Note that Localjob takes a hex value as the queue name. This is how the SysV
+adapter identifies different queues.
[sysv]: http://man7.org/linux/man-pages/man7/svipc.7.html
[blog]: http://sirupsen.com/unix-background-queue/