nesquena / backburner

Simple and reliable beanstalkd job queue for ruby
http://nesquena.github.com/backburner
MIT License
428 stars 68 forks source link

Added ability to handle all calls to an instance or class method asynchronously #98

Closed contentfree closed 9 years ago

contentfree commented 9 years ago

Inspired by same functionality in Delayed::Job. It enables a developer to make async decisions later (and potentially only in particular environments):

class Example
  def id; 1 end
  def hard_task; "Seriously, it's hard" end
end

# In a config file:
Backburner::Performable.handle_asynchronously(Example, :hard_task, pri: 123, queue: 'hard-jobs')

# Elsewhere in the code:
Example.new.hard_task # => will now be handled asynchronously automatically

The same can be done for static methods using Backburner::Performable.handle_static_asynchronously(Example, :a_static_method, {})

One edge case: If the producer and consumer aren't configured the same way, then this'll break, because the aliased method chain is actually what's enqueued – eg. the method enqueued is actually hard_task_without_async in our example. This should be fine in the vast majority of use cases, but something to note nonetheless.

contentfree commented 9 years ago

Ah dang. I always do this. I guess I'll have to close this, make some branches and push those as separate pull requests.

nesquena commented 9 years ago

This looks great, I want to spend some time reviewing soon and then will push a new release.

contentfree commented 9 years ago

I closed this one. Please see #100 (and #99, for lamba support for queue names)