module RocketJob::Plugins::Job::Throttle::ClassMethods
Public Instance Methods
define_throttle(method_name, filter: :throttle_filter_class)
click to toggle source
Add a new throttle.
Parameters:
method_name: [Symbol] Name of method to call to evaluate whether a throttle has been exceeded. Note: Must return true or false. filter: [Symbol|Proc] Name of method to call to return the filter when the throttle has been exceeded. Or, a block that will return the filter. Default: :throttle_filter_class (Throttle all jobs of this class)
Note: Throttles are executed in the order they are defined.
# File lib/rocket_job/plugins/job/throttle.rb, line 49 def define_throttle(method_name, filter: :throttle_filter_class) # Duplicate to prevent modifying parent class throttles definitions = rocket_job_throttles ? rocket_job_throttles.deep_dup : ThrottleDefinitions.new definitions.add(method_name, filter) self.rocket_job_throttles = definitions end
throttle?(method_name)
click to toggle source
Has a throttle been defined?
# File lib/rocket_job/plugins/job/throttle.rb, line 66 def throttle?(method_name) rocket_job_throttles&.exist?(method_name) end
undefine_throttle(method_name)
click to toggle source
Undefine a previously defined throttle
# File lib/rocket_job/plugins/job/throttle.rb, line 57 def undefine_throttle(method_name) return unless rocket_job_throttles definitions = rocket_job_throttles.deep_dup definitions.remove(method_name) self.rocket_job_throttles = definitions end