rails/rails — pull request #16699 by cristianbica (2014-08-26 08:04:55+00:00)
Title: [WIP] Active Job partial refactor

This (hopefully) cleans up a little the AJ: there were places where we passed job class, arguments, queue name, job id and I've converted everything to pass a job instance. Everything is backwards compatible and also I've added some syntax sugar :)
```ruby
# you can do the current way
MyJob.enqueue 'cristian'

#or
job = MyJob.new('cristian')
# do stuff with job
job.enqueue
job.enqueue in: 5.minutes
```
The other reason I've done this is to be able to enqueue the same job (class) to different queues:
```ruby
job = MyJob.new('cristian')
job.queue = :high_priority
job.enqueue
```
To be more clear in the job definition I would also change `queue_as` to `default_queue_as` although this brings a backward incompatibility.

We could also allow to pass the queue name in the instance method `.enqueue` and when you rescue from some error you could reschedule on another queue:
```ruby
class SiteScrapperJob
queue_as :default
rescue_from(MyException) do
retry_now queue: :low_priority
end
def perform(website)
#raises MyException if cannot load the site
end
end
```

If this is accepted I would like it to be merged after the integration tests are merged.

/cc @rafaelfranca @matthewd @dhh @seuros