Sha256: bec8f6cf569aebdf2edf850515a87b1521ff47a8301664b243da7b6944fe4e05
Contents?: true
Size: 891 Bytes
Versions: 2
Compression:
Stored size: 891 Bytes
Contents
require "resque/throttle" module Resque extend self # Raised when trying to create a job that is throttled class ThrottledError < RuntimeError; end def enqueue_with_throttle(klass, *args) if should_throttle?(klass, args) raise ThrottledError.new("#{klass} with key #{klass.key} has exceeded it's throttle limit") end enqueue_without_throttle(klass, args) end alias_method :enqueue_without_throttle, :enqueue alias_method :enqueue, :enqueue_with_throttle private def should_throttle?(klass, *args) return false if !throttle_job?(klass) || klass.disabled return true if key_found?(klass, args) redis.set(klass.key(args), true, klass.can_run_every) return false end def key_found?(klass, *args) redis.get(klass.key(args)) end def throttle_job?(klass) klass.ancestors.include?(Resque::ThrottledJob) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
resque-throttle-0.2.12 | lib/resque/resque.rb |
resque-throttle-0.2.11 | lib/resque/resque.rb |