Skip to content

Commit 04eea85

Browse files
Merge pull request #583 from Shopify/dont-renqueue-stopped-throttled-jobs
Don't re-enqueue stopped throttled jobs
2 parents 29b6d22 + 0a49c60 commit 04eea85

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Gemfile.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PATH
55
actionpack (>= 6.0)
66
activejob (>= 6.0)
77
activerecord (>= 6.0)
8-
job-iteration (~> 1.1)
8+
job-iteration (~> 1.3.6)
99
railties (>= 6.0)
1010

1111
GEM
@@ -98,10 +98,10 @@ GEM
9898
erubi (1.10.0)
9999
globalid (1.0.0)
100100
activesupport (>= 5.0)
101-
i18n (1.9.1)
101+
i18n (1.10.0)
102102
concurrent-ruby (~> 1.0)
103103
io-wait (0.2.1)
104-
job-iteration (1.3.5)
104+
job-iteration (1.3.6)
105105
activejob (>= 5.2)
106106
loofah (2.14.0)
107107
crass (~> 1.0.2)

app/jobs/concerns/maintenance_tasks/task_job_concern.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def reenqueue_iteration_job(should_ignore: true)
152152
def after_perform
153153
@run.persist_transition
154154
if defined?(@reenqueue_iteration_job) && @reenqueue_iteration_job
155-
reenqueue_iteration_job(should_ignore: false)
155+
reenqueue_iteration_job(should_ignore: false) unless @run.stopped?
156156
end
157157
end
158158

maintenance_tasks.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
2222
spec.add_dependency("actionpack", ">= 6.0")
2323
spec.add_dependency("activejob", ">= 6.0")
2424
spec.add_dependency("activerecord", ">= 6.0")
25-
spec.add_dependency("job-iteration", "~> 1.1")
25+
spec.add_dependency("job-iteration", "~> 1.3.6")
2626
spec.add_dependency("railties", ">= 6.0")
2727
end

test/jobs/maintenance_tasks/task_job_test.rb

+16
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,22 @@ class << self
407407
assert_predicate run.reload, :succeeded?
408408
end
409409

410+
test ".perform_now with a throttle doesn't enqueue a job if run is stopping" do
411+
run = Run.create!(task_name: "Maintenance::UpdatePostsThrottledTask")
412+
Maintenance::UpdatePostsThrottledTask.any_instance
413+
.expects(:process).once.with do
414+
run.cancelling!
415+
Maintenance::UpdatePostsThrottledTask.throttle = true
416+
end
417+
418+
TaskJob.perform_now(run)
419+
420+
assert_predicate(run.reload, :cancelled?)
421+
assert_empty(enqueued_jobs)
422+
ensure
423+
Maintenance::UpdatePostsThrottledTask.throttle = false
424+
end
425+
410426
test ".perform_now makes arguments supplied for Task parameters available" do
411427
post = Post.last
412428
Maintenance::ParamsTask.any_instance.expects(:process).once.with(post)

0 commit comments

Comments
 (0)