Commit ca9ed983 authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch 'refactor-shared-runners-seconds-4' into 'master'

Move last reset date of CI minutes behind abstraction method

See merge request gitlab-org/gitlab!71677
parents d7cb4b89 8825f453
...@@ -47,6 +47,14 @@ module Ci ...@@ -47,6 +47,14 @@ module Ci
end 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
end
end
def purchased_minutes def purchased_minutes
strong_memoize(:purchased_minutes) do strong_memoize(:purchased_minutes) do
namespace.extra_shared_runners_minutes_limit.to_i namespace.extra_shared_runners_minutes_limit.to_i
......
...@@ -79,8 +79,6 @@ module EE ...@@ -79,8 +79,6 @@ module EE
.or(where.not(last_ci_minutes_usage_notification_level: nil)) .or(where.not(last_ci_minutes_usage_notification_level: nil))
end end
delegate :shared_runners_seconds_last_reset, to: :namespace_statistics, allow_nil: true
delegate :additional_purchased_storage_size, :additional_purchased_storage_size=, delegate :additional_purchased_storage_size, :additional_purchased_storage_size=,
:additional_purchased_storage_ends_on, :additional_purchased_storage_ends_on=, :additional_purchased_storage_ends_on, :additional_purchased_storage_ends_on=,
:temporary_storage_increase_ends_on, :temporary_storage_increase_ends_on=, :temporary_storage_increase_ends_on, :temporary_storage_increase_ends_on=,
......
...@@ -190,8 +190,7 @@ module EE ...@@ -190,8 +190,7 @@ module EE
.order(excess_arel.desc) .order(excess_arel.desc)
end end
delegate :shared_runners_seconds, :shared_runners_seconds_last_reset, delegate :shared_runners_seconds, to: :statistics, allow_nil: true
to: :statistics, allow_nil: true
delegate :ci_minutes_quota, to: :shared_runners_limit_namespace delegate :ci_minutes_quota, to: :shared_runners_limit_namespace
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
.row .row
.col-sm-6 .col-sm-6
%strong %strong
- last_reset = namespace.shared_runners_seconds_last_reset - last_reset = minutes_quota.reset_date
- if last_reset - if last_reset
= s_('UsageQuota|Usage since') = s_('UsageQuota|Usage since')
= last_reset.strftime('%b %d, %Y') = last_reset.strftime('%b %d, %Y')
......
...@@ -15,7 +15,11 @@ FactoryBot.modify do ...@@ -15,7 +15,11 @@ FactoryBot.modify do
after(:create) do |namespace, evaluator| after(:create) do |namespace, evaluator|
if evaluator.ci_minutes_used if evaluator.ci_minutes_used
create(:ci_namespace_monthly_usage, namespace: namespace, amount_used: evaluator.ci_minutes_used) create(:ci_namespace_monthly_usage, namespace: namespace, amount_used: evaluator.ci_minutes_used)
create(:namespace_statistics, namespace: namespace, shared_runners_seconds: evaluator.ci_minutes_used.minutes)
create(:namespace_statistics,
namespace: namespace,
shared_runners_seconds: evaluator.ci_minutes_used.minutes,
shared_runners_seconds_last_reset: Time.current)
end end
end end
end end
......
...@@ -13,7 +13,7 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do ...@@ -13,7 +13,7 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do
end end
shared_examples 'resetting pipeline minutes' do shared_examples 'resetting pipeline minutes' do
context 'when namespace has namespace statistics' do context 'when namespace has minutes used' do
before do before do
set_ci_minutes_used(namespace, 100) set_ci_minutes_used(namespace, 100)
end end
...@@ -29,7 +29,7 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do ...@@ -29,7 +29,7 @@ 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.namespace_statistics.reload.shared_runners_seconds_last_reset).to be_like_time(time) expect(namespace.ci_minutes_quota.reset_date).to be_like_time(time)
end end
end end
end end
......
...@@ -189,7 +189,7 @@ RSpec.describe Ci::Minutes::Quota do ...@@ -189,7 +189,7 @@ RSpec.describe Ci::Minutes::Quota do
end end
end end
describe 'purchased_minutes_used_up?' do describe '#purchased_minutes_used_up?' do
subject { quota.purchased_minutes_used_up? } subject { quota.purchased_minutes_used_up? }
context 'when quota is enabled' do context 'when quota is enabled' do
...@@ -234,4 +234,20 @@ RSpec.describe Ci::Minutes::Quota do ...@@ -234,4 +234,20 @@ RSpec.describe Ci::Minutes::Quota do
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
end end
describe '#reset_date' do
subject(:reset_date) { quota.reset_date }
let(:reset_time) { Date.new(2021, 10, 14) }
let(:namespace) do
travel_to(reset_time) do
create(:namespace, :with_ci_minutes)
end
end
it 'corresponds to the reset time' do
expect(reset_date).to eq(reset_time)
end
end
end end
...@@ -20,7 +20,6 @@ RSpec.describe Namespace do ...@@ -20,7 +20,6 @@ RSpec.describe Namespace do
it { is_expected.to have_one :upcoming_reconciliation } it { is_expected.to have_one :upcoming_reconciliation }
it { is_expected.to have_many(:ci_minutes_additional_packs) } it { is_expected.to have_many(:ci_minutes_additional_packs) }
it { is_expected.to delegate_method(:shared_runners_seconds_last_reset).to(:namespace_statistics) }
it { is_expected.to delegate_method(:trial?).to(:gitlab_subscription) } it { is_expected.to delegate_method(:trial?).to(:gitlab_subscription) }
it { is_expected.to delegate_method(:trial_ends_on).to(:gitlab_subscription) } it { is_expected.to delegate_method(:trial_ends_on).to(:gitlab_subscription) }
it { is_expected.to delegate_method(:trial_starts_on).to(:gitlab_subscription) } it { is_expected.to delegate_method(:trial_starts_on).to(:gitlab_subscription) }
......
...@@ -11,7 +11,6 @@ RSpec.describe Project do ...@@ -11,7 +11,6 @@ RSpec.describe Project do
describe 'associations' do describe 'associations' do
it { is_expected.to delegate_method(:shared_runners_seconds).to(:statistics) } it { is_expected.to delegate_method(:shared_runners_seconds).to(:statistics) }
it { is_expected.to delegate_method(:shared_runners_seconds_last_reset).to(:statistics) }
it { is_expected.to delegate_method(:ci_minutes_quota).to(:shared_runners_limit_namespace) } it { is_expected.to delegate_method(:ci_minutes_quota).to(:shared_runners_limit_namespace) }
it { is_expected.to delegate_method(:shared_runners_minutes_limit_enabled?).to(:shared_runners_limit_namespace) } it { is_expected.to delegate_method(:shared_runners_minutes_limit_enabled?).to(:shared_runners_limit_namespace) }
......
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