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
e057e178
Commit
e057e178
authored
May 19, 2021
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify how we upsert pending builds to the queue
parent
250bb538
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
10 deletions
+39
-10
app/models/ci/pending_build.rb
app/models/ci/pending_build.rb
+3
-7
app/services/ci/update_build_queue_service.rb
app/services/ci/update_build_queue_service.rb
+1
-1
spec/models/ci/pending_build_spec.rb
spec/models/ci/pending_build_spec.rb
+33
-0
spec/services/ci/update_build_queue_service_spec.rb
spec/services/ci/update_build_queue_service_spec.rb
+2
-2
No files found.
app/models/ci/pending_build.rb
View file @
e057e178
...
...
@@ -7,16 +7,12 @@ module Ci
belongs_to
:project
belongs_to
:build
,
class_name:
'Ci::Build'
def
self
.
upsert!
(
build
)
def
self
.
upsert
_from_build
!
(
build
)
entry
=
self
.
new
(
build:
build
,
project:
build
.
project
)
raise
ArgumentError
,
'queuing entry invalid'
unless
entry
.
valid?
entry
.
validate!
attributes
=
{
build_id:
entry
.
build_id
,
project_id:
entry
.
project_id
}
ActiveRecord
::
InsertAll
.
new
(
self
,
[
attributes
],
on_duplicate: :skip
,
returning:
%w[build_id]
)
.
execute
self
.
upsert
(
entry
.
attributes
.
compact
,
returning:
%w[build_id]
,
unique_by: :build_id
)
end
end
end
app/services/ci/update_build_queue_service.rb
View file @
e057e178
...
...
@@ -19,7 +19,7 @@ module Ci
raise
InvalidQueueTransition
unless
transition
.
to
==
'pending'
transition
.
within_transaction
do
result
=
::
Ci
::
PendingBuild
.
upsert!
(
build
)
result
=
::
Ci
::
PendingBuild
.
upsert
_from_build
!
(
build
)
unless
result
.
empty?
metrics
.
increment_queue_operation
(
:build_queue_push
)
...
...
spec/models/ci/pending_build_spec.rb
0 → 100644
View file @
e057e178
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Ci
::
PendingBuild
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:build
)
{
create
(
:ci_build
,
:created
,
pipeline:
pipeline
)
}
describe
'.upsert_from_build!'
do
context
'another pending entry does not exist'
do
it
'creates a new pending entry'
do
result
=
described_class
.
upsert_from_build!
(
build
)
expect
(
result
.
rows
.
dig
(
0
,
0
)).
to
eq
build
.
id
expect
(
build
.
reload
.
queuing_entry
).
to
be_present
end
end
context
'when another queuing entry exists for given build'
do
before
do
described_class
.
create!
(
build:
build
,
project:
project
)
end
it
'returns a build id as a result'
do
result
=
described_class
.
upsert_from_build!
(
build
)
expect
(
result
.
rows
.
dig
(
0
,
0
)).
to
eq
build
.
id
end
end
end
end
spec/services/ci/update_build_queue_service_spec.rb
View file @
e057e178
...
...
@@ -47,10 +47,10 @@ RSpec.describe Ci::UpdateBuildQueueService do
::
Ci
::
PendingBuild
.
create!
(
build:
build
,
project:
project
)
end
it
'does nothing and returns
nil
'
do
it
'does nothing and returns
build id
'
do
queued
=
subject
.
push
(
build
,
transition
)
expect
(
queued
).
to
be_nil
expect
(
queued
).
to
eq
build
.
id
end
end
end
...
...
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