Module: SidekiqIteration::Iteration
- Includes:
- Enumerators
- Defined in:
- lib/sidekiq_iteration/iteration.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#current_run_iterations ⇒ Object
readonly
Returns the value of attribute current_run_iterations.
-
#cursor_position ⇒ Object
readonly
Returns the value of attribute cursor_position.
-
#executions ⇒ Object
readonly
Returns the value of attribute executions.
-
#start_time ⇒ Object
readonly
The time when the job starts running.
-
#times_interrupted ⇒ Object
readonly
Returns the value of attribute times_interrupted.
-
#total_time ⇒ Object
readonly
The total time the job has been running, including multiple iterations.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_enumerator ⇒ Enumerator
The enumerator to be iterated over.
-
#each_iteration ⇒ void
The action to be performed on each item from the enumerator.
- #initialize ⇒ Object
-
#on_complete ⇒ Object
A hook to override that will be called when the job finished iterating.
-
#on_resume ⇒ Object
A hook to override that will be called when the job resumes iterating.
-
#on_shutdown ⇒ Object
A hook to override that will be called each time the job is interrupted.
-
#on_start ⇒ Object
A hook to override that will be called when the job starts iterating.
- #perform(*arguments) ⇒ Object
Methods included from Enumerators
#active_record_batches_enumerator, #active_record_records_enumerator, #active_record_relations_enumerator, #array_enumerator, #csv_batches_enumerator, #csv_enumerator, #nested_enumerator
Instance Attribute Details
#current_run_iterations ⇒ Object (readonly)
Returns the value of attribute current_run_iterations.
57 58 59 |
# File 'lib/sidekiq_iteration/iteration.rb', line 57 def current_run_iterations @current_run_iterations end |
#cursor_position ⇒ Object (readonly)
Returns the value of attribute cursor_position.
57 58 59 |
# File 'lib/sidekiq_iteration/iteration.rb', line 57 def cursor_position @cursor_position end |
#executions ⇒ Object (readonly)
Returns the value of attribute executions.
57 58 59 |
# File 'lib/sidekiq_iteration/iteration.rb', line 57 def executions @executions end |
#start_time ⇒ Object (readonly)
The time when the job starts running. If the job is interrupted and runs again, the value is updated.
64 65 66 |
# File 'lib/sidekiq_iteration/iteration.rb', line 64 def start_time @start_time end |
#times_interrupted ⇒ Object (readonly)
Returns the value of attribute times_interrupted.
57 58 59 |
# File 'lib/sidekiq_iteration/iteration.rb', line 57 def times_interrupted @times_interrupted end |
#total_time ⇒ Object (readonly)
The total time the job has been running, including multiple iterations. The time isn’t reset if the job is interrupted.
68 69 70 |
# File 'lib/sidekiq_iteration/iteration.rb', line 68 def total_time @total_time end |
Class Method Details
.included(base) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sidekiq_iteration/iteration.rb', line 11 def self.included(base) base.extend(ClassMethods) base.extend(Throttling) base.class_eval do throttle_on(backoff: SidekiqIteration.default_retry_backoff) do |job| job.class.max_job_runtime && job.start_time && (Time.now.utc - job.start_time) > job.class.max_job_runtime end throttle_on(backoff: SidekiqIteration.default_retry_backoff) do defined?(Sidekiq::CLI) && Sidekiq::CLI.instance.launcher.stopping? end end super end |
Instance Method Details
#build_enumerator ⇒ Enumerator
The enumerator to be iterated over.
112 113 114 |
# File 'lib/sidekiq_iteration/iteration.rb', line 112 def build_enumerator(*) raise NotImplementedError, "#{self.class.name} must implement a 'build_enumerator' method" end |
#each_iteration ⇒ void
This method returns an undefined value.
The action to be performed on each item from the enumerator.
123 124 125 |
# File 'lib/sidekiq_iteration/iteration.rb', line 123 def each_iteration(*) raise NotImplementedError, "#{self.class.name} must implement an 'each_iteration' method" end |
#initialize ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/sidekiq_iteration/iteration.rb', line 71 def initialize super @arguments = nil @job_iteration_retry_backoff = SidekiqIteration.default_retry_backoff @needs_reenqueue = false @current_run_iterations = 0 end |
#on_complete ⇒ Object
A hook to override that will be called when the job finished iterating.
102 103 |
# File 'lib/sidekiq_iteration/iteration.rb', line 102 def on_complete end |
#on_resume ⇒ Object
A hook to override that will be called when the job resumes iterating.
92 93 |
# File 'lib/sidekiq_iteration/iteration.rb', line 92 def on_resume end |
#on_shutdown ⇒ Object
A hook to override that will be called each time the job is interrupted. This can be due to throttling (throttle enumerator), ‘max_job_runtime` configuration, or sidekiq restarting.
98 99 |
# File 'lib/sidekiq_iteration/iteration.rb', line 98 def on_shutdown end |
#on_start ⇒ Object
A hook to override that will be called when the job starts iterating. Is called only once, for the first time.
88 89 |
# File 'lib/sidekiq_iteration/iteration.rb', line 88 def on_start end |
#perform(*arguments) ⇒ Object
80 81 82 83 84 |
# File 'lib/sidekiq_iteration/iteration.rb', line 80 def perform(*arguments) (arguments) @arguments = arguments interruptible_perform(*arguments) end |