Commit e0d07579 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'mc/feature/track-last-ci-minute-update-correctly' into 'master'

Reset CI minutes for all namespaces

See merge request gitlab-org/gitlab!38057
parents 99afaa62 ece44622
......@@ -80,15 +80,13 @@ module Ci
end
def reset_shared_runners_seconds!(namespaces)
NamespaceStatistics
.for_namespaces(namespaces)
.with_any_ci_minutes_used
.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
::ProjectStatistics
.for_namespaces(namespaces)
.with_any_ci_minutes_used
.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
namespace_relation = NamespaceStatistics.for_namespaces(namespaces)
namespace_relation = namespace_relation.with_any_ci_minutes_used unless ::Gitlab::Ci::Features.reset_ci_minutes_for_all_namespaces?
namespace_relation.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
project_relation = ::ProjectStatistics.for_namespaces(namespaces)
project_relation = project_relation.with_any_ci_minutes_used unless ::Gitlab::Ci::Features.reset_ci_minutes_for_all_namespaces?
project_relation.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
end
def reset_ci_minutes_notifications!(namespaces)
......
---
title: Reset CI minutes for all namespaces every month.
merge_request: 38057
author:
type: changed
......@@ -85,6 +85,17 @@ RSpec.describe Ci::Minutes::BatchResetService do
expect(namespace.last_ci_minutes_usage_notification_level).to be_nil
end
end
it 'touches the shared_runners_seconds_last_reset for all namespaces' do
subject
expect(
[
namespace_1.reload, namespace_2.reload, namespace_3.reload,
namespace_4.reload, namespace_5.reload
].map(&:shared_runners_seconds_last_reset)
).to all(be_within(1.second).of(Time.current))
end
end
context 'when ID range is not provided' do
......@@ -110,6 +121,17 @@ RSpec.describe Ci::Minutes::BatchResetService do
expect(namespace_6.last_ci_minutes_notification_at).to be_nil
expect(namespace_6.last_ci_minutes_usage_notification_level).to be_nil
end
it 'touches the shared_runners_seconds_last_reset for all namespaces' do
subject
expect(
[
namespace_1.reload, namespace_2.reload, namespace_3.reload,
namespace_4.reload, namespace_5.reload, namespace_6.reload
].map(&:shared_runners_seconds_last_reset)
).to all(be_within(1.second).of(Time.current))
end
end
context 'when an ActiveRecordError is raised' do
......
......@@ -85,6 +85,10 @@ module Gitlab
def self.job_entry_matches_all_keys?
::Feature.enabled?(:ci_job_entry_matches_all_keys)
end
def self.reset_ci_minutes_for_all_namespaces?
::Feature.enabled?(:reset_ci_minutes_for_all_namespaces, default_enabled: false)
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