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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
063a8c8c
Commit
063a8c8c
authored
May 13, 2021
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add queue push/pop methods to build queue service
parent
65e2046e
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
178 additions
and
120 deletions
+178
-120
app/models/ci/build.rb
app/models/ci/build.rb
+6
-4
app/services/ci/update_build_queue_service.rb
app/services/ci/update_build_queue_service.rb
+23
-18
app/workers/build_queue_worker.rb
app/workers/build_queue_worker.rb
+1
-1
spec/services/ci/update_build_queue_service_spec.rb
spec/services/ci/update_build_queue_service_spec.rb
+148
-97
No files found.
app/models/ci/build.rb
View file @
063a8c8c
...
...
@@ -294,18 +294,20 @@ module Ci
end
end
after_transition
any
=>
[
:pending
]
do
|
build
|
Ci
::
UpdateBuildQueueService
.
new
.
queue_push!
(
build
)
# rubocop:disable CodeReuse/ServiceClass
after_transition
any
=>
[
:pending
]
do
|
build
,
transition
|
Ci
::
UpdateBuildQueueService
.
new
.
push
(
build
,
transition
)
build
.
run_after_commit
do
BuildQueueWorker
.
perform_async
(
id
)
end
end
after_transition
pending:
any
do
|
build
|
after_transition
pending:
any
do
|
build
,
transition
|
# TODO ensure that there is no race condition here, add test for this
Ci
::
UpdateBuildQueueService
.
new
.
queue_pop!
(
build
)
Ci
::
UpdateBuildQueueService
.
new
.
pop
(
build
,
transition
)
end
# rubocop:enable CodeReuse/ServiceClass
after_transition
pending: :running
do
|
build
|
build
.
deployment
&
.
run
...
...
app/services/ci/update_build_queue_service.rb
View file @
063a8c8c
...
...
@@ -2,45 +2,50 @@
module
Ci
class
UpdateBuildQueueService
InvalidQueueTransition
=
Class
.
new
(
StandardError
)
attr_reader
:metrics
def
initialize
(
metrics
=
::
Gitlab
::
Ci
::
Queue
::
Metrics
)
@metrics
=
metrics
end
##
# Add a build to the pending builds queue
#
def
queue_push!
(
build
,
metrics
=
::
Gitlab
::
Ci
::
Queue
::
Metrics
)
in_transaction
do
::
Ci
::
PendingBuild
.
create!
(
build:
build
,
project:
project
)
def
push
(
build
,
transition
)
raise
InvalidQueueTransition
unless
transition
.
to
==
'pending'
# TODO increment pending builds counter
transition
.
within_transaction
do
::
Ci
::
PendingBuild
.
create!
(
build:
build
,
project:
build
.
project
)
end
# TODO increment pending builds counter
end
##
# Remove a build from the pending builds queue
#
def
queue_pop!
(
build
,
metrics
=
::
Gitlab
::
Ci
::
Queue
::
Metrics
)
in_transaction
do
::
Ci
::
PendingBuild
.
find
(
build
.
id
).
destroy!
def
pop
(
build
,
transition
)
raise
InvalidQueueTransition
unless
transition
.
from
==
'pending'
# TODO decrement pending builds counter
transition
.
within_transaction
do
::
Ci
::
PendingBuild
.
find_by
(
build_id:
build
.
id
)
&
.
destroy!
# rubocop:disable CodeReuse/ActiveRecord
end
# TODO decrement pending builds counter
end
##
# Unblock runner associated with given project / build
#
def
execute
(
build
,
metrics
=
::
Gitlab
::
Ci
::
Queue
::
Metrics
)
tick_for
(
build
,
build
.
project
.
all_runners
,
metrics
)
def
tick
(
build
)
tick_for
(
build
,
build
.
project
.
all_runners
)
end
private
def
in_transaction
# TODO ensure that state machine transition transaction is open
#
yield
end
def
tick_for
(
build
,
runners
,
metrics
)
def
tick_for
(
build
,
runners
)
runners
=
runners
.
with_recent_runner_queue
runners
=
runners
.
with_tags
if
Feature
.
enabled?
(
:ci_preload_runner_tags
,
default_enabled: :yaml
)
...
...
app/workers/build_queue_worker.rb
View file @
063a8c8c
...
...
@@ -14,7 +14,7 @@ class BuildQueueWorker # rubocop:disable Scalability/IdempotentWorker
# rubocop: disable CodeReuse/ActiveRecord
def
perform
(
build_id
)
Ci
::
Build
.
find_by
(
id:
build_id
).
try
do
|
build
|
Ci
::
UpdateBuildQueueService
.
new
.
execute
(
build
)
Ci
::
UpdateBuildQueueService
.
new
.
tick
(
build
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
spec/services/ci/update_build_queue_service_spec.rb
View file @
063a8c8c
This diff is collapsed.
Click to expand it.
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