class TResque::Delay::InvocationProxy

Public Class Methods

new(object, options = {}) click to toggle source
# File lib/tresque/delay.rb, line 45
def initialize(object, options = {})

  @object = object
  @run_at = options[:run_at]
  @run_at ||= (!!options[:force] ? true : nil)
  @synchronous = !!options[:synchronous]

  @queue_namespace  = options[:queue_namespace] || Util.calculate_namespace_from_class(object)
  @queue_name       = options[:queue] || 'default'

  @lock_namespace   = options[:lock_namespace]
  @queue_lock_key   = options[:queue_lock_key]
  @worker_lock_key  = options[:worker_lock_key]
end

Public Instance Methods

method_missing(method_name, *args) click to toggle source
# File lib/tresque/delay.rb, line 60
def method_missing(method_name, *args)
  if !@synchronous && (!in_resque? || @run_at == true || @run_at.to_i > Time.now.to_i)
    @method_name = method_name.to_s
    @args = args
    queue_delayed_invocation!
  else
    @object.send(method_name, *args)
  end
end
respond_to?(*args) click to toggle source
# File lib/tresque/delay.rb, line 70
def respond_to?(*args)
  return true unless in_resque?
  @object.respond_to?(*args)
end

Protected Instance Methods

in_resque?() click to toggle source
# File lib/tresque/delay.rb, line 77
def in_resque?
  !!(ENV['QUEUE'] || ENV['QUEUES'])
end
queue_delayed_invocation!() click to toggle source
# File lib/tresque/delay.rb, line 81
def queue_delayed_invocation!
  push = {}

  if @object.is_a?(Class)
    push["class_name"] = @object.name
  else
    push["class_name"] = @object.class.name
    push["id"] = @object.respond_to?(:delay_id) ? @object.delay_id : @object.id
  end

  push["method_name"]     = @method_name
  push["args"]            = @args
  push["queue_namespace"] = @queue_namespace
  push["queue"]           = @queue_name
  push["run_at"]          = @run_at             if @run_at && @run_at != true
  push["lock_namespace"]  = @lock_namespace     if @lock_namespace

  if @queue_lock_key
    push["queue_lock"]          = @queue_lock_key.to_s
    push[@queue_lock_key.to_s]  = push["id"]
  end

  if @worker_lock_key
    push["worker_lock"]         = @worker_lock_key.to_s
    push[@worker_lock_key.to_s] = push["id"]
  end

  TResque::DelayExecutionWorker.enqueue(push)
end