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
51fe0bd6
Commit
51fe0bd6
authored
Jan 28, 2021
by
Fabio Pitino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move UpdateBuildMinutesService under CI
parent
322d1214
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
44 deletions
+46
-44
.rubocop_manual_todo.yml
.rubocop_manual_todo.yml
+0
-2
ee/app/services/ci/minutes/update_build_minutes_service.rb
ee/app/services/ci/minutes/update_build_minutes_service.rb
+42
-0
ee/app/services/update_build_minutes_service.rb
ee/app/services/update_build_minutes_service.rb
+0
-38
ee/app/workers/ee/build_finished_worker.rb
ee/app/workers/ee/build_finished_worker.rb
+1
-1
ee/spec/models/ci/build_spec.rb
ee/spec/models/ci/build_spec.rb
+1
-1
ee/spec/services/ci/minutes/update_build_minutes_service_spec.rb
.../services/ci/minutes/update_build_minutes_service_spec.rb
+2
-2
No files found.
.rubocop_manual_todo.yml
View file @
51fe0bd6
...
...
@@ -198,7 +198,6 @@ Rails/SaveBang:
-
'
ee/spec/services/start_pull_mirroring_service_spec.rb'
-
'
ee/spec/services/status_page/trigger_publish_service_spec.rb'
-
'
ee/spec/services/todo_service_spec.rb'
-
'
ee/spec/services/update_build_minutes_service_spec.rb'
-
'
ee/spec/services/vulnerability_feedback/create_service_spec.rb'
-
'
ee/spec/support/protected_tags/access_control_shared_examples.rb'
-
'
ee/spec/support/shared_examples/features/protected_branches_access_control_shared_examples.rb'
...
...
@@ -2530,7 +2529,6 @@ Gitlab/NamespacedClass:
-
'
ee/app/services/ldap_group_reset_service.rb'
-
'
ee/app/services/start_pull_mirroring_service.rb'
-
'
ee/app/services/timebox_report_service.rb'
-
'
ee/app/services/update_build_minutes_service.rb'
-
'
ee/app/uploaders/issuable_metric_image_uploader.rb'
-
'
ee/app/validators/host_validator.rb'
-
'
ee/app/validators/ldap_filter_validator.rb'
...
...
ee/app/services/ci/minutes/update_build_minutes_service.rb
0 → 100644
View file @
51fe0bd6
# frozen_string_literal: true
module
Ci
module
Minutes
class
UpdateBuildMinutesService
<
BaseService
def
execute
(
build
)
return
unless
build
.
shared_runners_minutes_limit_enabled?
return
unless
build
.
complete?
return
unless
build
.
duration
&
.
positive?
count_projects_based_on_cost_factors
(
build
)
end
private
def
count_projects_based_on_cost_factors
(
build
)
cost_factor
=
build
.
runner
.
minutes_cost_factor
(
project
.
visibility_level
)
duration_with_cost_factor
=
(
build
.
duration
*
cost_factor
).
to_i
return
unless
duration_with_cost_factor
>
0
ProjectStatistics
.
update_counters
(
project_statistics
,
shared_runners_seconds:
duration_with_cost_factor
)
NamespaceStatistics
.
update_counters
(
namespace_statistics
,
shared_runners_seconds:
duration_with_cost_factor
)
end
def
namespace_statistics
namespace
.
namespace_statistics
||
namespace
.
create_namespace_statistics
end
def
project_statistics
project
.
statistics
||
project
.
create_statistics
(
namespace:
project
.
namespace
)
end
def
namespace
project
.
shared_runners_limit_namespace
end
end
end
end
ee/app/services/update_build_minutes_service.rb
deleted
100644 → 0
View file @
322d1214
# frozen_string_literal: true
class
UpdateBuildMinutesService
<
BaseService
def
execute
(
build
)
return
unless
build
.
shared_runners_minutes_limit_enabled?
return
unless
build
.
complete?
return
unless
build
.
duration
&
.
positive?
count_projects_based_on_cost_factors
(
build
)
end
private
def
count_projects_based_on_cost_factors
(
build
)
cost_factor
=
build
.
runner
.
minutes_cost_factor
(
project
.
visibility_level
)
duration_with_cost_factor
=
(
build
.
duration
*
cost_factor
).
to_i
return
unless
duration_with_cost_factor
>
0
ProjectStatistics
.
update_counters
(
project_statistics
,
shared_runners_seconds:
duration_with_cost_factor
)
NamespaceStatistics
.
update_counters
(
namespace_statistics
,
shared_runners_seconds:
duration_with_cost_factor
)
end
def
namespace_statistics
namespace
.
namespace_statistics
||
namespace
.
create_namespace_statistics
end
def
project_statistics
project
.
statistics
||
project
.
create_statistics
(
namespace:
project
.
namespace
)
end
def
namespace
project
.
shared_runners_limit_namespace
end
end
ee/app/workers/ee/build_finished_worker.rb
View file @
51fe0bd6
...
...
@@ -3,7 +3,7 @@
module
EE
module
BuildFinishedWorker
def
process_build
(
build
)
UpdateBuildMinutesService
.
new
(
build
.
project
,
nil
).
execute
(
build
)
::
Ci
::
Minutes
::
UpdateBuildMinutesService
.
new
(
build
.
project
,
nil
).
execute
(
build
)
# We need to use `reset` on `project` because their AR associations have been cached
# and `Namespace#namespace_statistics` will return stale data.
::
Ci
::
Minutes
::
EmailNotificationService
.
new
(
build
.
project
.
reset
).
execute
if
::
Gitlab
.
com?
...
...
ee/spec/models/ci/build_spec.rb
View file @
51fe0bd6
...
...
@@ -98,7 +98,7 @@ RSpec.describe Ci::Build do
%w(success drop cancel)
.
each
do
|
event
|
it
"for event
#{
event
}
"
,
:sidekiq_might_not_need_inline
do
expect
(
UpdateBuildMinutesService
)
expect
(
Ci
::
Minutes
::
UpdateBuildMinutesService
)
.
to
receive
(
:new
).
and_call_original
job
.
public_send
(
event
)
...
...
ee/spec/services/update_build_minutes_service_spec.rb
→
ee/spec/services/
ci/minutes/
update_build_minutes_service_spec.rb
View file @
51fe0bd6
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
UpdateBuildMinutesService
do
RSpec
.
describe
Ci
::
Minutes
::
UpdateBuildMinutesService
do
describe
'#perform'
do
let
(
:namespace
)
{
create
(
:namespace
,
shared_runners_minutes_limit:
100
)
}
let
(
:project
)
{
create
(
:project
,
:public
,
namespace:
namespace
)
}
...
...
@@ -31,7 +31,7 @@ RSpec.describe UpdateBuildMinutesService do
context
'when statistics are created'
do
before
do
project
.
statistics
.
update
(
shared_runners_seconds:
100
)
project
.
statistics
.
update
!
(
shared_runners_seconds:
100
)
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
100
)
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