Module: RocketJob::Batch::Throttle::ClassMethods
- Defined in:
- lib/rocket_job/batch/throttle.rb
Instance Method Summary collapse
-
#batch_throttle?(method_name) ⇒ Boolean
Has a throttle been defined?.
-
#define_batch_throttle(method_name, filter: :throttle_filter_class, description: nil) ⇒ Object
Add a new throttle.
-
#undefine_batch_throttle(method_name) ⇒ Object
Undefine a previously defined throttle.
Instance Method Details
#batch_throttle?(method_name) ⇒ Boolean
Has a throttle been defined?
71 72 73 |
# File 'lib/rocket_job/batch/throttle.rb', line 71 def batch_throttle?(method_name) rocket_job_batch_throttles.exist?(method_name) end |
#define_batch_throttle(method_name, filter: :throttle_filter_class, description: nil) ⇒ Object
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)
description: [String|Proc]
Human readable reason why the job is throttled, persisted to `throttled_by`
and shown in Mission Control. A Proc is called with the job and slice and
must return a String. Default: a humanized version of the method name.
Note: Throttles are executed in the order they are defined.
54 55 56 57 58 59 |
# File 'lib/rocket_job/batch/throttle.rb', line 54 def define_batch_throttle(method_name, filter: :throttle_filter_class, description: nil) # Duplicate to prevent modifying parent class throttles definitions = rocket_job_batch_throttles ? rocket_job_batch_throttles.dup : ThrottleDefinitions.new definitions.add(method_name, filter, description) self.rocket_job_batch_throttles = definitions end |
#undefine_batch_throttle(method_name) ⇒ Object
Undefine a previously defined throttle
62 63 64 65 66 67 68 |
# File 'lib/rocket_job/batch/throttle.rb', line 62 def undefine_batch_throttle(method_name) return unless rocket_job_batch_throttles definitions = rocket_job_batch_throttles.dup definitions.remove(method_name) self.rocket_job_batch_throttles = definitions end |