Sha256: 85b7d0049f00cdfa0fba6ecb9d47379c8e88c0557ec16612fcda804568216060
Contents?: true
Size: 1001 Bytes
Versions: 1
Compression:
Stored size: 1001 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) unless klass.throttle_settings[:silent] raise( ThrottledError, "#{klass} with key #{klass.key(*args)} has exceeded it's throttle limit" ) end else enqueue_without_throttle(klass, *args) end 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.setex(klass.key(*args), klass.can_run_every, true) 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fhwang-resque-throttle-0.3.0 | lib/resque/resque.rb |