Skip to content

Commit

Permalink
remove throttling stub, change Sidekiq::Job#stopping? to Sidekiq::Job…
Browse files Browse the repository at this point in the history
…#interrupted?, less likely to collide with user APIs
  • Loading branch information
mperham committed Jun 27, 2024
1 parent cdc7644 commit adaf1f5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/sidekiq/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def logger
Sidekiq.logger
end

def stopping?
def interrupted?
@_context&.stopping?
end

Expand Down
25 changes: 1 addition & 24 deletions lib/sidekiq/job/iterable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def on_resume

# A hook to override that will be called each time the job is interrupted.
#
# This can be due to interruption, throttling or sidekiq stopping.
# This can be due to interruption or sidekiq stopping.
#
def on_stop
end
Expand Down Expand Up @@ -86,25 +86,6 @@ def each_iteration(*)
raise NotImplementedError, "#{self.class.name} must implement an '#each_iteration' method"
end

# A hook to override that can be used to throttle a job when a given condition is met.
#
# If a job is throttled, it will be interrupted and retried after a backoff period
# (0 by default) has passed.
#
# The backoff can be configured via `sidekiq_options` per job:
#
# sidekiq_options iteration: { retry_backoff: 30 } # in seconds
#
# or globally:
#
# Sidekiq::Config::DEFAULTS[:iteration][:retry_backoff] = 30 # in seconds
#
# @return [Boolean]
#
def throttle?
false
end

def iteration_key
"it-#{jid}"
end
Expand Down Expand Up @@ -211,10 +192,6 @@ def build_enumerator(params, cursor:)
end
end

def interrupted?
_context&.stopping? || throttle?
end

def flush_state
key = iteration_key
state = {
Expand Down
2 changes: 1 addition & 1 deletion test/iterable/iterable_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def each_iteration(number)
@current_run_iterations += 1
end

def throttle?
def interrupted?
@current_run_iterations == stop_after_iterations
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ForeverJob

def perform
count = 0
until count > 1000 && stopping?
until count > 1000 && interrupted?
count += 1
end
count
Expand Down Expand Up @@ -130,7 +130,7 @@ def call(*args)
end

it "can detect when stopping" do
refute MySetJob.new.stopping?
refute MySetJob.new.interrupted?
end

it "stops on command" do
Expand Down

0 comments on commit adaf1f5

Please sign in to comment.