Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
e1f05b93
Commit
e1f05b93
authored
Aug 12, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use explicit events to transition between states
parent
8acbc9e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
13 deletions
+33
-13
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+32
-12
app/models/commit_status.rb
app/models/commit_status.rb
+1
-1
No files found.
app/models/ci/pipeline.rb
View file @
e1f05b93
...
@@ -20,6 +20,14 @@ module Ci
...
@@ -20,6 +20,14 @@ 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
transition
:created
=>
:pending
end
event
:run
do
transition
[
:pending
,
:success
,
:failed
,
:canceled
,
:skipped
]
=>
:running
end
event
:skip
do
event
:skip
do
transition
any
=>
:skipped
transition
any
=>
:skipped
end
end
...
@@ -28,13 +36,12 @@ module Ci
...
@@ -28,13 +36,12 @@ module Ci
transition
any
=>
:failed
transition
any
=>
:failed
end
end
event
:update_status
do
event
:succeed
do
transition
any
=>
:pending
,
if:
->
(
pipeline
)
{
pipeline
.
can_transition_to?
(
'pending'
)
}
transition
any
=>
:success
transition
any
=>
:running
,
if:
->
(
pipeline
)
{
pipeline
.
can_transition_to?
(
'running'
)
}
end
transition
any
=>
:failed
,
if:
->
(
pipeline
)
{
pipeline
.
can_transition_to?
(
'failed'
)
}
transition
any
=>
:success
,
if:
->
(
pipeline
)
{
pipeline
.
can_transition_to?
(
'success'
)
}
event
:cancel
do
transition
any
=>
:canceled
,
if:
->
(
pipeline
)
{
pipeline
.
can_transition_to?
(
'canceled'
)
}
transition
any
=>
:canceled
transition
any
=>
:skipped
,
if:
->
(
pipeline
)
{
pipeline
.
can_transition_to?
(
'skipped'
)
}
end
end
after_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
after_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
...
@@ -214,23 +221,36 @@ module Ci
...
@@ -214,23 +221,36 @@ module Ci
Ci
::
ProcessPipelineService
.
new
(
project
,
user
).
execute
(
self
)
Ci
::
ProcessPipelineService
.
new
(
project
,
user
).
execute
(
self
)
end
end
def
build_updated
case
latest_builds_status
when
'pending'
queue
when
'running'
run
when
'success'
succeed
when
'failed'
drop
when
'canceled'
cancel
when
'skipped'
skip
end
end
def
predefined_variables
def
predefined_variables
[
[
{
key:
'CI_PIPELINE_ID'
,
value:
id
.
to_s
,
public:
true
}
{
key:
'CI_PIPELINE_ID'
,
value:
id
.
to_s
,
public:
true
}
]
]
end
end
def
can_transition_to?
(
expected_status
)
latest_status
==
expected_status
end
def
update_duration
def
update_duration
update
(
duration:
statuses
.
latest
.
duration
)
update
(
duration:
statuses
.
latest
.
duration
)
end
end
private
private
def
latest_status
def
latest_
builds_
status
return
'failed'
unless
yaml_errors
.
blank?
return
'failed'
unless
yaml_errors
.
blank?
statuses
.
latest
.
status
||
'skipped'
statuses
.
latest
.
status
||
'skipped'
...
...
app/models/commit_status.rb
View file @
e1f05b93
...
@@ -70,7 +70,7 @@ class CommitStatus < ActiveRecord::Base
...
@@ -70,7 +70,7 @@ class CommitStatus < ActiveRecord::Base
end
end
after_transition
do
|
commit_status
,
transition
|
after_transition
do
|
commit_status
,
transition
|
commit_status
.
pipeline
.
try
(
:
update_status
)
unless
transition
.
loopback?
commit_status
.
pipeline
.
try
(
:
build_updated
)
unless
transition
.
loopback?
end
end
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
commit_status
|
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
commit_status
|
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment