0.0
No commit activity in last 3 years
No release in over 3 years
Simple way of invoking methods asynchronously using resque.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
>= 0

Runtime

>= 0
 Project Readme

ResqueAsync

A simple way to invoke methods asynchronously using Resque. There are a few gems that provide similar functionality. However this this implementation provides more expressive syntax that it gives the caller control over the invocation.

Installation

Add this line to your application's Gemfile:

gem 'resque-async'

And then execute:

$ bundle

Or install it yourself as:

$ gem install resque-async

Usage

Assuming

class MyObject < ActiveRecord::Base
    def self.slow_class_method
    end
    def slow_instance_method
    end
end

Supports Class Methods and ActiveRecord instance methods

MyObject.async(:high).slow_class_method

# ActiveRecord instances will be queued/loaded/invoked asynchronously
MyObject.new.async(:medium).slow_instance_method

Natural synchronous invocation

    MyObject.slow_class_method
    MyObject.new.slow_instance_method

Support high, medium, low priority out of the box. As well as custom worker/queue

# slow_class_method queued/invoked on 'high' queue
MyObject.async(:high).slow_class_method

# slow_class_method queued/invoked on 'medium' queue
MyObject.async(:medium).slow_class_method

# slow_class_method queued/invoked on 'low' queue
MyObject.async(:low).slow_class_method

OR

class MyCustomerWorker
    extend ResqueAsync::Workers::AsyncClassWorker
    @queue :crazy
end 
MyObject.async(MyCustomerWorker).crazy_priority

What about resque-async-method?

resque-async-method hides the fact that a method may be invoked asynchronously. From the caller's perspective things can get really confusing.

With resque-async-method

class MyObject < ActiveRecord::Base
    def slow_method
    end
    async_method :slow_method
end

# is this async or not? What does result equal? Better check the implementation of MyObject
result = MyObject.new.slow_method 

With resque-async

class MyObject < ActiveRecord::Base
    def slow_method
    end
end

# this should be pretty obvious, even years later, that slow_method is invoked async
d = MyObject.new.async(:low).slow_method

Contributing

  1. Fork it ( https://github.com/exitround/resque-async/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request