Sha256: 3e2291c80c2bbba363c1ead4b7969e184aa7f0ba4d9dc8c725f71e0980309196

Contents?: true

Size: 740 Bytes

Versions: 5

Compression:

Stored size: 740 Bytes

Contents

require 'sidekiq/extensions/generic_proxy'

module Sidekiq
  module Extensions
    ##
    # Adds a 'delay' method to all Classes to offload class method
    # execution to Sidekiq.  Examples:
    #
    # User.delay.delete_inactive
    # Wikipedia.delay.download_changes_for(Date.today)
    #
    class DelayedClass
      include Sidekiq::Worker

      def perform(yml)
        (target, method_name, args) = YAML.load(yml)
        target.send(method_name, *args)
      end
    end

    module Klass
      def delay
        Proxy.new(DelayedClass, self)
      end
      def delay_for(interval)
        Proxy.new(DelayedClass, self, Time.now.to_f + interval.to_f)
      end
    end

  end
end

Class.send(:include, Sidekiq::Extensions::Klass)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sidekiq-2.3.2 lib/sidekiq/extensions/class_methods.rb
sidekiq-2.3.1 lib/sidekiq/extensions/class_methods.rb
sidekiq-2.3.0 lib/sidekiq/extensions/class_methods.rb
sidekiq-2.2.1 lib/sidekiq/extensions/class_methods.rb
sidekiq-2.2.0 lib/sidekiq/extensions/class_methods.rb