2012-02-17 15:54:11 -08:00
|
|
|
module Sidekiq
|
|
|
|
module Extensions
|
2012-04-01 19:53:45 -07:00
|
|
|
class Proxy < (RUBY_VERSION < '1.9' ? Object : BasicObject)
|
2012-05-25 20:21:42 -07:00
|
|
|
def initialize(performable, target, at=nil)
|
2012-02-17 15:54:11 -08:00
|
|
|
@performable = performable
|
|
|
|
@target = target
|
2012-05-25 20:21:42 -07:00
|
|
|
@at = at
|
2012-02-17 15:54:11 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(name, *args)
|
|
|
|
# Sidekiq has a limitation in that its message must be JSON.
|
|
|
|
# JSON can't round trip real Ruby objects so we use YAML to
|
|
|
|
# serialize the objects to a String. The YAML will be converted
|
|
|
|
# to JSON and then deserialized on the other side back into a
|
|
|
|
# Ruby object.
|
|
|
|
obj = [@target, name, args]
|
2012-05-25 20:21:42 -07:00
|
|
|
if @at
|
|
|
|
@performable.perform_at(@at, ::YAML.dump(obj))
|
|
|
|
else
|
|
|
|
@performable.perform_async(::YAML.dump(obj))
|
|
|
|
end
|
2012-02-17 15:54:11 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|