Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/models/shipit/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,17 @@ def sync_github_if_necessary
)

def self.refresh_deployed_revisions
find_each.select(&:supports_fetch_deployed_revision?).each(&:async_refresh_deployed_revision)
# where.not avoids deserializing every stack's cached_deploy_spec each
# minute: a stack without a cached spec cannot have fetch steps.
not_archived
.where.not(cached_deploy_spec: nil)
.find_each
.select(&:supports_fetch_deployed_revision?)
.each(&:async_refresh_deployed_revision)
end

def self.schedule_continuous_delivery
where(continuous_deployment: true).find_each do |stack|
not_archived.where(continuous_deployment: true).find_each do |stack|
ContinuousDeliveryJob.perform_later(stack)
end
end
Expand Down
32 changes: 32 additions & 0 deletions test/models/shipit/stack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@ def setup
GithubHook.any_instance.stubs(:teardown!)
end

test ".schedule_continuous_delivery skips archived stacks" do
archived = shipit_stacks(:archived_6hours_ago)
archived.update!(continuous_deployment: true)
@stack.update!(continuous_deployment: true)

Stack.schedule_continuous_delivery

enqueued_args = enqueued_jobs
.select { |job| job[:job] == ContinuousDeliveryJob }
.map { |job| job[:args].to_s }
assert enqueued_args.any? { |args| args.include?("Stack/#{@stack.id}") },
"expected a ContinuousDeliveryJob for the active stack"
refute enqueued_args.any? { |args| args.include?("Stack/#{archived.id}") },
"archived stacks must not trigger continuous delivery"
end

test ".refresh_deployed_revisions skips archived stacks" do
archived = shipit_stacks(:archived_6hours_ago)
archived.update!(cached_deploy_spec: DeploySpec.new('fetch' => ['echo 1']))
@stack.update!(cached_deploy_spec: DeploySpec.new('fetch' => ['echo 1']))

Stack.refresh_deployed_revisions

enqueued_args = enqueued_jobs
.select { |job| job[:job] == FetchDeployedRevisionJob }
.map { |job| job[:args].to_s }
assert enqueued_args.any? { |args| args.include?("Stack/#{@stack.id}") },
"expected a FetchDeployedRevisionJob for the active stack with fetch steps"
refute enqueued_args.any? { |args| args.include?("Stack/#{archived.id}") },
"archived stacks must not refresh deployed revisions"
end

test "branch defaults to default branch name" do
@stack.branch = ""
Shipit.github.api.expects(:repo).with("shopify/shipit-engine").returns(
Expand Down
Loading