Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (33 sloc) 0.949 kB
require 'sidekiq/extensions/generic_proxy'
module Sidekiq
module Extensions
##
# Adds a 'delay' method to all Classes to offload class method
# execution to Sidekiq. Examples:
#
# User.delay.delete_inactive
# Wikipedia.delay.download_changes_for(Date.today)
#
class DelayedClass
include Sidekiq::Worker
def perform(*msg)
(target, method_name, args) = ArgsSerializer.deserialize_message(*msg)
target.send(method_name, *args)
end
end
module Klass
def delay(options={})
Proxy.new(DelayedClass, self, options)
end
def delay_for(interval, options={})
options = options.reverse_merge(at: Time.now.to_f + interval.to_f)
delay(options)
end
def sidekiq_serialize
"SIDEKIQ@#{self.name}"
end
end
end
end
Class.send(:include, Sidekiq::Extensions::Klass)
Module.send(:include, Sidekiq::Extensions::Klass)
Jump to Line
Something went wrong with that request. Please try again.