2012-02-17 18:54:11 -05:00
|
|
|
module Sidekiq
|
|
|
|
module Extensions
|
2012-04-01 22:53:45 -04:00
|
|
|
class Proxy < (RUBY_VERSION < '1.9' ? Object : BasicObject)
|
2012-02-17 18:54:11 -05:00
|
|
|
def initialize(performable, target)
|
|
|
|
@performable = performable
|
|
|
|
@target = target
|
|
|
|
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-03-10 14:56:34 -05:00
|
|
|
@performable.perform_async(::YAML.dump(obj))
|
2012-02-17 18:54:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|