Commit 9d438709 authored by Matija Čupić's avatar Matija Čupić

Reset CI minutes for all namespaces

Resets CI minutes for all namespaces and projects regardless if they
used any minutes or not.
parent 2a5ebef6
......@@ -18,7 +18,6 @@ class ProjectStatistics < ApplicationRecord
scope :for_project_ids, ->(project_ids) { where(project_id: project_ids) }
scope :for_namespaces, -> (namespaces) { where(namespace: namespaces) }
scope :with_any_ci_minutes_used, -> { where.not(shared_runners_seconds: 0) }
def total_repository_size
repository_size + lfs_objects_size
......
......@@ -6,7 +6,6 @@ class NamespaceStatistics < ApplicationRecord
validates :namespace, presence: true
scope :for_namespaces, -> (namespaces) { where(namespace: namespaces) }
scope :with_any_ci_minutes_used, -> { where.not(shared_runners_seconds: 0) }
def shared_runners_minutes(include_extra: true)
minutes = shared_runners_seconds.to_i / 60
......
......@@ -82,12 +82,10 @@ module Ci
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)
end
......
......@@ -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
......
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