0.01
No release in over 3 years
Low commit activity in last 3 years
Allow you to quickly move a long call to background which then executed by resque
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

delayed-method

Requires the resque gem.

Allows you to move a long running method to background to be processed later by resque

I have to come up with this because all other resque based delayed execution gems out there that I have tried are complex, buggy and don't work.

delayed-method is designed to be dead simple, and doesn't hack deep into resque itself (so it is more likely to continue to work, even with further internal change of resque)

In fact, it just relies on Resque.enqueue at the deepest level. It doesn't deal with serialization, so it won't have any problem with serialization

Installation

$ gem install delayed-method

Usage

Given you have this long call inside your web request:

Executor.long_call(arg1, arg2)

then you can easily move it to the delayed queue in background with this:

DelayedMethod.enqueue(Executor, :long_call, arg1, arg2)

Or if you use active record model:

model.long_call(arg1, arg2)

then you can easily move it to the delayed queue in background with this:

DelayedMethod.enqueue(model, :long_call, arg1, arg2)

That's it. This is the only two cases where DelayedMethod will work: Caller needs to be either a class or a persisted ActiveRecord model

If you use resque-scheduler, you can also do this:

DelayedMethod.enqueue_at(1.day.from_now, Executor, :long_call, arg1, arg2)

or

DelayedMethod.enqueue_at(1.day.from_now, model, :long_call, arg1, arg2)

Customize your worker

If you want to customize DelayedMethod to enforce things like having ActiveRecord reading from master instead of slave, you can do this:

   class MyCustomDelayedMethod < DelayedMethod
     @queue = :delayed

     def perform(*args)
       wrap_method do
         super
       end
     end
   end

   MyCustomDelayedMethod.enqueue(object, :method)

Warning

Please notice that Class method call and ActiveRecord instance call are the only two cases supported. Even in those cases, only simple arguments (string, number) are supported. Using object, structure, or symbol as argument will yield unexpected results. (Symbol will be converted to String).

Author

Phuong Nguyen:: phuongnd08@gmail.com