Commit 369c4ca1 authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch 'refator-shared-runners-seconds-5' into 'master'

Use feature flag for new CI minutes monthly tracking

See merge request gitlab-org/gitlab!72116
parents c9b2853f f0daab46
...@@ -41,17 +41,21 @@ module Ci ...@@ -41,17 +41,21 @@ module Ci
def total_minutes_used def total_minutes_used
strong_memoize(:total_minutes_used) do strong_memoize(:total_minutes_used) do
# TODO: use namespace.new_monthly_ci_minutes_enabled? to switch to if namespace.new_monthly_ci_minutes_enabled?
# ::Ci::Minutes::NamespaceMonthlyUsage.find_or_create_current(namespace.id).amount_used.to_i current_usage.amount_used.to_i
namespace.namespace_statistics&.shared_runners_seconds.to_i / 60 else
namespace.namespace_statistics&.shared_runners_seconds.to_i / 60
end
end end
end end
def reset_date def reset_date
strong_memoize(:reset_date) do strong_memoize(:reset_date) do
# TODO: use namespace.new_monthly_ci_minutes_enabled? to switch to if namespace.new_monthly_ci_minutes_enabled?
# ::Ci::Minutes::NamespaceMonthlyUsage.find_or_create_current(namespace.id).date current_usage.date
namespace.namespace_statistics&.shared_runners_seconds_last_reset else
namespace.namespace_statistics&.shared_runners_seconds_last_reset
end
end end
end end
...@@ -102,6 +106,10 @@ module Ci ...@@ -102,6 +106,10 @@ module Ci
private private
def current_usage
@current_usage ||= ::Ci::Minutes::NamespaceMonthlyUsage.find_or_create_current(namespace_id: namespace.id)
end
def monthly_minutes_available? def monthly_minutes_available?
total_minutes_used <= monthly_minutes total_minutes_used <= monthly_minutes
end end
......
...@@ -29,7 +29,8 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do ...@@ -29,7 +29,8 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do
expect(current_path).to include(namespace.path) expect(current_path).to include(namespace.path)
expect(namespace.reload.ci_minutes_quota.total_minutes_used).to eq(0) 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 end
end end
......
...@@ -238,16 +238,26 @@ RSpec.describe Ci::Minutes::Quota do ...@@ -238,16 +238,26 @@ RSpec.describe Ci::Minutes::Quota do
describe '#reset_date' do describe '#reset_date' do
subject(:reset_date) { quota.reset_date } subject(:reset_date) { quota.reset_date }
let(:reset_time) { Date.new(2021, 10, 14) } let(:current_time) { Date.new(2021, 10, 14) }
let(:namespace) do let(:namespace) do
travel_to(reset_time) do travel_to(current_time) do
create(:namespace, :with_ci_minutes) create(:namespace, :with_ci_minutes)
end end
end end
it 'corresponds to the reset time' do it 'corresponds to the beginning of the current month' do
expect(reset_date).to eq(reset_time) 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 end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment