class RocketJob::ThrottleDefinitions
Attributes
throttles[RW]
Public Class Methods
new()
click to toggle source
# File lib/rocket_job/throttle_definitions.rb, line 5 def initialize @throttles = [] end
Public Instance Methods
add(method_name, filter)
click to toggle source
# File lib/rocket_job/throttle_definitions.rb, line 9 def add(method_name, filter) unless filter.is_a?(Symbol) || filter.is_a?(Proc) raise(ArgumentError, "Filter for #{method_name} must be a Symbol or Proc") end raise(ArgumentError, "Cannot define #{method_name} twice, undefine previous throttle first") if exist?(method_name) @throttles += [ThrottleDefinition.new(method_name, filter)] end
deep_dup()
click to toggle source
# File lib/rocket_job/throttle_definitions.rb, line 39 def deep_dup new_defination = dup new_defination.throttles = throttles.map(&:dup) new_defination end
exist?(method_name)
click to toggle source
Has a throttle been defined?
# File lib/rocket_job/throttle_definitions.rb, line 24 def exist?(method_name) throttles.any? { |throttle| throttle.method_name == method_name } end
matching_filter(job, *args)
click to toggle source
Returns the matching filter, or nil if no throttles were triggered.
# File lib/rocket_job/throttle_definitions.rb, line 30 def matching_filter(job, *args) throttles.each do |throttle| next unless throttle.throttled?(job, *args) return throttle.extract_filter(job, *args) end nil end
remove(method_name)
click to toggle source
Undefine a previously defined throttle
# File lib/rocket_job/throttle_definitions.rb, line 19 def remove(method_name) throttles.delete_if { |throttle| throttle.method_name == method_name } end