Commit ea4ac578 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Use event `enqueue` instead of `queue`

parent d7b68151
...@@ -59,7 +59,7 @@ module Ci ...@@ -59,7 +59,7 @@ module Ci
when: build.when, when: build.when,
user: user, user: user,
environment: build.environment, environment: build.environment,
status_event: 'queue' status_event: 'enqueue'
) )
MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build) MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build)
new_build new_build
...@@ -102,7 +102,7 @@ module Ci ...@@ -102,7 +102,7 @@ module Ci
def play(current_user = nil) def play(current_user = nil)
# Try to queue a current build # Try to queue a current build
if self.queue if self.enqueue
self.update(user: current_user) self.update(user: current_user)
self self
else else
......
...@@ -20,7 +20,7 @@ module Ci ...@@ -20,7 +20,7 @@ module Ci
after_save :keep_around_commits after_save :keep_around_commits
state_machine :status, initial: :created do state_machine :status, initial: :created do
event :queue do event :enqueue do
transition created: :pending transition created: :pending
transition any - [:created, :pending] => :running transition any - [:created, :pending] => :running
end end
...@@ -224,18 +224,12 @@ module Ci ...@@ -224,18 +224,12 @@ module Ci
def build_updated def build_updated
case latest_builds_status case latest_builds_status
when 'pending' when 'pending' then enqueue
queue when 'running' then run
when 'running' when 'success' then succeed
run when 'failed' then drop
when 'success' when 'canceled' then cancel
succeed when 'skipped' then skip
when 'failed'
drop
when 'canceled'
cancel
when 'skipped'
skip
end end
end end
......
...@@ -26,7 +26,7 @@ class CommitStatus < ActiveRecord::Base ...@@ -26,7 +26,7 @@ class CommitStatus < ActiveRecord::Base
scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) } scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) }
state_machine :status do state_machine :status do
event :queue do event :enqueue do
transition [:created, :skipped] => :pending transition [:created, :skipped] => :pending
end end
......
...@@ -37,7 +37,7 @@ module Ci ...@@ -37,7 +37,7 @@ module Ci
return false unless Statuseable::COMPLETED_STATUSES.include?(current_status) return false unless Statuseable::COMPLETED_STATUSES.include?(current_status)
if valid_statuses_for_when(build.when).include?(current_status) if valid_statuses_for_when(build.when).include?(current_status)
build.queue build.enqueue
true true
else else
build.skip build.skip
......
...@@ -886,8 +886,10 @@ describe Ci::Build, models: true do ...@@ -886,8 +886,10 @@ describe Ci::Build, models: true do
is_expected.to eq(build) is_expected.to eq(build)
end end
context 'for success build' do context 'for successful build' do
before { build.queue } before do
build.success
end
it 'creates a new build' do it 'creates a new build' do
is_expected.to be_pending is_expected.to be_pending
......
...@@ -143,7 +143,7 @@ describe Ci::Pipeline, models: true do ...@@ -143,7 +143,7 @@ describe Ci::Pipeline, models: true do
expect(pipeline.reload.started_at).not_to be_nil expect(pipeline.reload.started_at).not_to be_nil
end end
it 'do not update on transitioning to success' do it 'does not update on transitioning to success' do
build.success build.success
expect(pipeline.reload.started_at).to be_nil expect(pipeline.reload.started_at).to be_nil
...@@ -157,7 +157,7 @@ describe Ci::Pipeline, models: true do ...@@ -157,7 +157,7 @@ describe Ci::Pipeline, models: true do
expect(pipeline.reload.finished_at).not_to be_nil expect(pipeline.reload.finished_at).not_to be_nil
end end
it 'do not update on transitioning to running' do it 'does not update on transitioning to running' do
build.run build.run
expect(pipeline.reload.finished_at).to be_nil expect(pipeline.reload.finished_at).to be_nil
...@@ -257,14 +257,16 @@ describe Ci::Pipeline, models: true do ...@@ -257,14 +257,16 @@ describe Ci::Pipeline, models: true do
subject { pipeline.reload.status } subject { pipeline.reload.status }
context 'on queuing' do context 'on queuing' do
before { build.queue } before do
build.enqueue
end
it { is_expected.to eq('pending') } it { is_expected.to eq('pending') }
end end
context 'on run' do context 'on run' do
before do before do
build.queue build.enqueue
build.run build.run
end end
...@@ -294,5 +296,18 @@ describe Ci::Pipeline, models: true do ...@@ -294,5 +296,18 @@ describe Ci::Pipeline, models: true do
it { is_expected.to eq('canceled') } it { is_expected.to eq('canceled') }
end end
context 'on failure and build retry' do
before do
build.drop
Ci::Build.retry(build)
end
# We are changing a state: created > failed > running
# Instead of: created > failed > pending
# Since the pipeline already run, so it should not be pending anymore
it { is_expected.to eq('running') }
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment