diff --git a/app/jobs/shipit/continuous_delivery_job.rb b/app/jobs/shipit/continuous_delivery_job.rb index de5c1b4b3..46a292f01 100644 --- a/app/jobs/shipit/continuous_delivery_job.rb +++ b/app/jobs/shipit/continuous_delivery_job.rb @@ -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 diff --git a/app/models/shipit/stack.rb b/app/models/shipit/stack.rb index 8e93a8e6b..78f2a2047 100644 --- a/app/models/shipit/stack.rb +++ b/app/models/shipit/stack.rb @@ -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 diff --git a/test/models/shipit/stacks_test.rb b/test/models/shipit/stacks_test.rb index dbfe5bb9a..b0f041f12 100644 --- a/test/models/shipit/stacks_test.rb +++ b/test/models/shipit/stacks_test.rb @@ -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)