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
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
......
......@@ -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
......
......@@ -238,16 +238,26 @@ RSpec.describe Ci::Minutes::Quota do
describe '#reset_date' do
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
travel_to(reset_time) do
travel_to(current_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
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