Skip to content

Instantly share code, notes, and snippets.

@EddM
Last active February 3, 2016 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EddM/4162cb98a43f3bc15788 to your computer and use it in GitHub Desktop.
Save EddM/4162cb98a43f3bc15788 to your computer and use it in GitHub Desktop.
module Delayable
def delay_instance_method(method_name, *args)
Sidekiq::Client.enqueue DelayedInstanceMethodWorker, class.to_s, id, method_name.to_s, args
end
end
class DelayedInstanceMethodWorker
include Sidekiq::Worker
def perform(klass, record_id, method_name, args = [])
if object = klass.constantize.find(record_id)
object.send(method_name, *args)
end
end
end
class Widget < ActiveRecord::Base
include Delayable
# ...
def foo
delay_instance_method(:do_something_funky, 123)
end
def do_something_funky(bar)
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment