2012-02-17 18:54:11 -05:00
|
|
|
module Sidekiq
|
|
|
|
module Extensions
|
2012-07-20 23:11:33 -04:00
|
|
|
class Proxy < BasicObject
|
2012-10-17 13:17:19 -04:00
|
|
|
def initialize(performable, target, options={})
|
2012-02-17 18:54:11 -05:00
|
|
|
@performable = performable
|
|
|
|
@target = target
|
2012-10-17 13:17:19 -04:00
|
|
|
@opts = options
|
2012-02-17 18:54:11 -05: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-10-17 13:17:19 -04:00
|
|
|
@performable.client_push({ 'class' => @performable, 'args' => [::YAML.dump(obj)] }.merge(@opts))
|
2012-02-17 18:54:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|