Skip to content

Commit f0e8263

Browse files
committed
Exclude archived stacks from the scheduler loops
Stack.schedule_continuous_delivery and Stack.refresh_deployed_revisions run every minute from the host application's scheduler, but neither scope excluded archived stacks. Archiving locks a stack, so the jobs were guaranteed no-ops: ContinuousDeliveryJob bails on the lock and FetchDeployedRevisionJob refreshes state nobody can see. At Shopify's scale that was ~1300 archived stacks enqueuing ~2000 no-op ContinuousDeliveryJobs per minute, plus full git clones from FetchDeployedRevisionJob for archived stacks with fetch steps, all on the same worker pool as deploys. Unarchiving already triggers a GithubSyncJob via sync_github_if_necessary, so a revived stack re-enters both loops naturally.
1 parent 635a50d commit f0e8263

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

app/models/shipit/stack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ def sync_github_if_necessary
117117
)
118118

119119
def self.refresh_deployed_revisions
120-
find_each.select(&:supports_fetch_deployed_revision?).each(&:async_refresh_deployed_revision)
120+
not_archived.find_each.select(&:supports_fetch_deployed_revision?).each(&:async_refresh_deployed_revision)
121121
end
122122

123123
def self.schedule_continuous_delivery
124-
where(continuous_deployment: true).find_each do |stack|
124+
not_archived.where(continuous_deployment: true).find_each do |stack|
125125
ContinuousDeliveryJob.perform_later(stack)
126126
end
127127
end

test/models/shipit/stack_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,36 @@ def setup
1111
GithubHook.any_instance.stubs(:teardown!)
1212
end
1313

14+
test ".schedule_continuous_delivery skips archived stacks" do
15+
archived = shipit_stacks(:archived_6hours_ago)
16+
archived.update!(continuous_deployment: true)
17+
@stack.update!(continuous_deployment: true)
18+
19+
Stack.schedule_continuous_delivery
20+
21+
enqueued_args = enqueued_jobs
22+
.select { |job| job[:job] == ContinuousDeliveryJob }
23+
.map { |job| job[:args].to_s }
24+
assert enqueued_args.any? { |args| args.include?("Stack/#{@stack.id}") },
25+
"expected a ContinuousDeliveryJob for the active stack"
26+
refute enqueued_args.any? { |args| args.include?("Stack/#{archived.id}") },
27+
"archived stacks must not trigger continuous delivery"
28+
end
29+
30+
test ".refresh_deployed_revisions skips archived stacks" do
31+
archived = shipit_stacks(:archived_6hours_ago)
32+
archived.update!(cached_deploy_spec: DeploySpec.new('fetch' => ['echo 1']))
33+
34+
Stack.refresh_deployed_revisions
35+
36+
enqueued_args = enqueued_jobs
37+
.select { |job| job[:job] == FetchDeployedRevisionJob }
38+
.map { |job| job[:args].to_s }
39+
assert enqueued_args.any?, "expected FetchDeployedRevisionJobs for active stacks with fetch steps"
40+
refute enqueued_args.any? { |args| args.include?("Stack/#{archived.id}") },
41+
"archived stacks must not refresh deployed revisions"
42+
end
43+
1444
test "branch defaults to default branch name" do
1545
@stack.branch = ""
1646
Shipit.github.api.expects(:repo).with("shopify/shipit-engine").returns(

0 commit comments

Comments
 (0)