jondot/sneakers — pull request #26 by MarkyMarkMcDonald (2014-02-14 21:42:34+00:00)
Title: Features/enqueue

Hi Jon,

the main aim of these two pull requests is to expose an `.enqueue` method on the Workers classes, so that if you have this `FooWorker` class:

```ruby
class FooWorker
include Sneakers::Worker
from_queue :my_queue

def work(msg)
put msg
ack!
end
end
```

All you need to do to enqueue a new job that will be processed by this worker is:

```ruby
FooWorker.enqueue(msg)
```

This is what the _second_ 633769c pull request does.

The _first_ 548ad9f pull request removes the `env` from the configuration options and queue naming, as per the discussions in issue #6. Hence, we got rid also of `Sneaker.not_environmental!`. This was deemed necessary to develop the new `.enqueue` feature because of the discrepancy between the queue names workers and publishers used (i.e. publishers would use the queue names _with_ the `env`, workers would not).

We have kept the same approach that you have on `Sneakers.publish`, i.e. we set the publisher as a class instance variable, as you can see from [here](https://github.com/pivotal/sneakers/blob/548ad9f78da0505108d818a79aee91305c6bdd39/lib/sneakers/worker.rb#L127).

As per now, there are publishers:

* On `Sneakers`
* On individual worker instances
* On worker classes (added by us)

We believe a better solution would be to build a publishers' pool, that can then be used across all project. However, this is out of the scope of this pull request.

M & R