Last active
February 3, 2016 23:35
-
-
Save EddM/4162cb98a43f3bc15788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Delayable | |
def delay_instance_method(method_name, *args) | |
Sidekiq::Client.enqueue DelayedInstanceMethodWorker, class.to_s, id, method_name.to_s, args | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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