Sha256: 455bc3c9efd8b233f6808684c29f0c234a64d2fc07ef97e83481710c6fae7b0b

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

module Delayed
  class DelayProxy < ActiveSupport::BasicObject
    def initialize(target, options)
      @target = target
      @options = options
    end

    def method_missing(method, *args)
      Job.create({
        :payload_object => PerformableMethod.new(@target, method.to_sym, args),
        :priority       => ::Delayed::Worker.default_priority
      }.merge(@options))
    end
  end

  module MessageSending
    def delay(options = {})
      DelayProxy.new(self, options)
    end
    alias __delay__ delay
    
    def send_later(method, *args)
      warn "[DEPRECATION] `object.send_later(:method)` is deprecated. Use `object.delay.method"
      __delay__.__send__(method, *args)
    end

    def send_at(time, method, *args)
      warn "[DEPRECATION] `object.send_at(time, :method)` is deprecated. Use `object.delay(:run_at => time).method"
      __delay__(:run_at => time).__send__(method, *args)
    end
    
    module ClassMethods
      def handle_asynchronously(method, opts = {})
        aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
        with_method, without_method = "#{aliased_method}_with_delay#{punctuation}", "#{aliased_method}_without_delay#{punctuation}"
        define_method(with_method) do |*args|
          curr_opts = opts.clone
          curr_opts.each_key do |key|
            if (val = curr_opts[key]).is_a?(Proc)
              curr_opts[key] = if val.arity == 1
                val.call(self)
              else
                val.call
              end
            end
          end
          delay(curr_opts).__send__(without_method, *args)
        end
        alias_method_chain method, :delay
      end
    end
  end                               
end

Version data entries

11 entries across 11 versions & 5 rubygems

Version Path
delayed_job-2.0.8 lib/delayed/message_sending.rb
delayed_job_csi-2.0.7 lib/delayed/message_sending.rb
delayed-job-ajaycb-2.0.10 lib/delayed/message_sending.rb
delayed_job_with_named_queues-2.0.7.3 lib/delayed/message_sending.rb
delayed_job_with_named_queues-2.0.7.2 lib/delayed/message_sending.rb
delayed_job_with_named_queues-2.0.7.1 lib/delayed/message_sending.rb
yetanothernguyen-delayed_job-0.0.1 lib/delayed/message_sending.rb
delayed_job-2.0.7 lib/delayed/message_sending.rb
delayed_job-2.0.6 lib/delayed/message_sending.rb
delayed_job-2.0.5 lib/delayed/message_sending.rb
delayed_job-2.0.4 lib/delayed/message_sending.rb