Skip to content

Commit

Permalink
Merge pull request #1309 from Shopify/rdj/continuous-delivery-job
Browse files Browse the repository at this point in the history
Update `ContinuousDeliveryJob` to account for concurrent tasks
  • Loading branch information
ruionweb committed May 31, 2023
2 parents 5b3fc47 + 40825cd commit e932100
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/jobs/shipit/continuous_delivery_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class ContinuousDeliveryJob < BackgroundJob

def perform(stack)
return unless stack.continuous_deployment?
return if stack.active_task?

# checks if there are any tasks running, including concurrent tasks
return if stack.occupied?

stack.trigger_continuous_delivery
end
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/shipit/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ def active_task
@active_task ||= tasks.current
end

def occupied?
!!occupied
end

def occupied
@occupied ||= tasks.active.last
end

def locked?
lock_reason.present?
end
Expand Down
30 changes: 30 additions & 0 deletions test/models/shipit/stacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,36 @@ def self.deliver(event, stack, payload)
end
end

test "#active_task? is false if stack has a concurrent deploy in active state" do
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new, force: true)
refute @stack.active_task?
end

test "#occupied? is false if stack has no deploy in either pending or running state" do
@stack.deploys.active.destroy_all
refute @stack.occupied?
end

test "#occupied? is false if stack has no deploy at all" do
@stack.deploys.destroy_all
refute @stack.occupied?
end

test "occupied? is true if stack has a concurrent deploy in active state" do
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new, force: true)
assert @stack.occupied?
end

test "occupied? is true if stack has a deploy in pending state" do
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new)
assert @stack.occupied?
end

test "#occupied? is true if a rollback is ongoing" do
shipit_deploys(:shipit_complete).trigger_rollback(AnonymousUser.new)
assert @stack.occupied?
end

test "#deployable? returns true if the stack is not locked, not awaiting provision, and is not deploying" do
@stack.deploys.destroy_all
@stack.update!(lock_reason: nil, awaiting_provision: false)
Expand Down

0 comments on commit e932100

Please sign in to comment.