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
f0daab46
Commit
f0daab46
authored
Oct 19, 2021
by
Fabio Pitino
Committed by
Luke Duncalfe
Oct 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use feature flag for new CI minutes monthly tracking
https://gitlab.com/gitlab-org/gitlab/-/issues/277448
parent
7bc0cb82
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
11 deletions
+30
-11
ee/app/models/ci/minutes/quota.rb
ee/app/models/ci/minutes/quota.rb
+14
-6
ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
+2
-1
ee/spec/models/ci/minutes/quota_spec.rb
ee/spec/models/ci/minutes/quota_spec.rb
+14
-4
No files found.
ee/app/models/ci/minutes/quota.rb
View file @
f0daab46
...
...
@@ -41,17 +41,21 @@ module Ci
def
total_minutes_used
strong_memoize
(
:total_minutes_used
)
do
# TODO: use namespace.new_monthly_ci_minutes_enabled? to switch to
# ::Ci::Minutes::NamespaceMonthlyUsage.find_or_create_current(namespace.id).amount_used.to_i
namespace
.
namespace_statistics
&
.
shared_runners_seconds
.
to_i
/
60
if
namespace
.
new_monthly_ci_minutes_enabled?
current_usage
.
amount_used
.
to_i
else
namespace
.
namespace_statistics
&
.
shared_runners_seconds
.
to_i
/
60
end
end
end
def
reset_date
strong_memoize
(
:reset_date
)
do
# TODO: use namespace.new_monthly_ci_minutes_enabled? to switch to
# ::Ci::Minutes::NamespaceMonthlyUsage.find_or_create_current(namespace.id).date
namespace
.
namespace_statistics
&
.
shared_runners_seconds_last_reset
if
namespace
.
new_monthly_ci_minutes_enabled?
current_usage
.
date
else
namespace
.
namespace_statistics
&
.
shared_runners_seconds_last_reset
end
end
end
...
...
@@ -102,6 +106,10 @@ module Ci
private
def
current_usage
@current_usage
||=
::
Ci
::
Minutes
::
NamespaceMonthlyUsage
.
find_or_create_current
(
namespace_id:
namespace
.
id
)
end
def
monthly_minutes_available?
total_minutes_used
<=
monthly_minutes
end
...
...
ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
View file @
f0daab46
...
...
@@ -29,7 +29,8 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do
expect
(
current_path
).
to
include
(
namespace
.
path
)
expect
(
namespace
.
reload
.
ci_minutes_quota
.
total_minutes_used
).
to
eq
(
0
)
expect
(
namespace
.
ci_minutes_quota
.
reset_date
).
to
be_like_time
(
time
)
expect
(
namespace
.
ci_minutes_quota
.
reset_date
.
month
).
to
eq
(
time
.
month
)
expect
(
namespace
.
ci_minutes_quota
.
reset_date
.
year
).
to
eq
(
time
.
year
)
end
end
end
...
...
ee/spec/models/ci/minutes/quota_spec.rb
View file @
f0daab46
...
...
@@ -238,16 +238,26 @@ RSpec.describe Ci::Minutes::Quota do
describe
'#reset_date'
do
subject
(
:reset_date
)
{
quota
.
reset_date
}
let
(
:
rese
t_time
)
{
Date
.
new
(
2021
,
10
,
14
)
}
let
(
:
curren
t_time
)
{
Date
.
new
(
2021
,
10
,
14
)
}
let
(
:namespace
)
do
travel_to
(
rese
t_time
)
do
travel_to
(
curren
t_time
)
do
create
(
:namespace
,
:with_ci_minutes
)
end
end
it
'corresponds to the reset time'
do
expect
(
reset_date
).
to
eq
(
reset_time
)
it
'corresponds to the beginning of the current month'
do
expect
(
reset_date
).
to
eq
(
Date
.
new
(
2021
,
10
,
1
))
end
context
'when feature flag ci_use_new_monthly_minutes is disabled'
do
before
do
stub_feature_flags
(
ci_use_new_monthly_minutes:
false
)
end
it
'corresponds to the current time'
do
expect
(
reset_date
).
to
eq
(
current_time
)
end
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