Class: GoodJob::ActiveJobExtensions::Concurrency::Rule
- Inherits:
-
Object
- Object
- GoodJob::ActiveJobExtensions::Concurrency::Rule
- Defined in:
- lib/good_job/active_job_extensions/concurrency.rb
Instance Attribute Summary collapse
-
#enqueue_limit ⇒ Object
readonly
Returns the value of attribute enqueue_limit.
-
#enqueue_throttle ⇒ Object
readonly
Returns the value of attribute enqueue_throttle.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#perform_limit ⇒ Object
readonly
Returns the value of attribute perform_limit.
-
#perform_throttle ⇒ Object
readonly
Returns the value of attribute perform_throttle.
-
#total_limit ⇒ Object
readonly
Returns the value of attribute total_limit.
Instance Method Summary collapse
- #evaluate(job, stage) ⇒ Object
-
#initialize(config) ⇒ Rule
constructor
A new instance of Rule.
- #key ⇒ Object
Constructor Details
#initialize(config) ⇒ Rule
Returns a new instance of Rule.
21 22 23 24 25 26 27 28 29 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 21 def initialize(config) @label = config[:label] @key = config.key?(:key) ? config[:key] : GoodJob::NONE @total_limit = config[:total_limit] @enqueue_limit = config[:enqueue_limit] @perform_limit = config[:perform_limit] @enqueue_throttle = config[:enqueue_throttle] @perform_throttle = config[:perform_throttle] end |
Instance Attribute Details
#enqueue_limit ⇒ Object (readonly)
Returns the value of attribute enqueue_limit.
19 20 21 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 19 def enqueue_limit @enqueue_limit end |
#enqueue_throttle ⇒ Object (readonly)
Returns the value of attribute enqueue_throttle.
19 20 21 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 19 def enqueue_throttle @enqueue_throttle end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
19 20 21 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 19 def label @label end |
#perform_limit ⇒ Object (readonly)
Returns the value of attribute perform_limit.
19 20 21 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 19 def perform_limit @perform_limit end |
#perform_throttle ⇒ Object (readonly)
Returns the value of attribute perform_throttle.
19 20 21 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 19 def perform_throttle @perform_throttle end |
#total_limit ⇒ Object (readonly)
Returns the value of attribute total_limit.
19 20 21 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 19 def total_limit @total_limit end |
Instance Method Details
#evaluate(job, stage) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/good_job/active_job_extensions/concurrency.rb', line 35 def evaluate(job, stage) resolved_key = resolve_key(job) resolved_label = resolve_label(job) return nil if resolved_key.blank? && resolved_label.blank? if stage == :enqueue enqueue_limit = resolve_limit(job, @enqueue_limit) || resolve_limit(job, @total_limit) enqueue_throttle = resolve_throttle(job, @enqueue_throttle) return nil unless enqueue_limit || enqueue_throttle check_enqueue(enqueue_limit, enqueue_throttle, job, resolved_key, resolved_label, enqueue_limit_flag: @enqueue_limit.present?) elsif stage == :perform perform_limit = resolve_limit(job, @perform_limit) || resolve_limit(job, @total_limit) perform_throttle = resolve_throttle(job, @perform_throttle) return nil unless perform_limit || perform_throttle check_perform(perform_limit, perform_throttle, job, resolved_key, resolved_label) end end |