Sha256: 4b732de81542eacb70b35b9b3eaf947cefc4bc9ff02f9d6871154badc971b001

Contents?: true

Size: 710 Bytes

Versions: 6

Compression:

Stored size: 710 Bytes

Contents

require 'sidekiq/extensions/generic_proxy'

module Sidekiq
  module Extensions
    ##
    # Adds a 'delay' method to ActiveRecord to offload arbitrary method
    # execution to Sidekiq.  Examples:
    #
    # User.delay.delete_inactive
    # User.recent_signups.each { |user| user.delay.mark_as_awesome }
    class DelayedModel
      include Sidekiq::Worker

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

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sidekiq-2.1.1 lib/sidekiq/extensions/active_record.rb
sidekiq-2.1.0 lib/sidekiq/extensions/active_record.rb
sidekiq-2.0.3 lib/sidekiq/extensions/active_record.rb
sidekiq-2.0.2 lib/sidekiq/extensions/active_record.rb
sidekiq-2.0.1 lib/sidekiq/extensions/active_record.rb
sidekiq-2.0.0 lib/sidekiq/extensions/active_record.rb