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 ...@@ -18,7 +18,6 @@ class ProjectStatistics < ApplicationRecord
scope :for_project_ids, ->(project_ids) { where(project_id: project_ids) } scope :for_project_ids, ->(project_ids) { where(project_id: project_ids) }
scope :for_namespaces, -> (namespaces) { where(namespace: namespaces) } scope :for_namespaces, -> (namespaces) { where(namespace: namespaces) }
scope :with_any_ci_minutes_used, -> { where.not(shared_runners_seconds: 0) }
def total_repository_size def total_repository_size
repository_size + lfs_objects_size repository_size + lfs_objects_size
......
...@@ -6,7 +6,6 @@ class NamespaceStatistics < ApplicationRecord ...@@ -6,7 +6,6 @@ class NamespaceStatistics < ApplicationRecord
validates :namespace, presence: true validates :namespace, presence: true
scope :for_namespaces, -> (namespaces) { where(namespace: namespaces) } 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) def shared_runners_minutes(include_extra: true)
minutes = shared_runners_seconds.to_i / 60 minutes = shared_runners_seconds.to_i / 60
......
...@@ -82,12 +82,10 @@ module Ci ...@@ -82,12 +82,10 @@ module Ci
def reset_shared_runners_seconds!(namespaces) def reset_shared_runners_seconds!(namespaces)
NamespaceStatistics NamespaceStatistics
.for_namespaces(namespaces) .for_namespaces(namespaces)
.with_any_ci_minutes_used
.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current) .update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
::ProjectStatistics ::ProjectStatistics
.for_namespaces(namespaces) .for_namespaces(namespaces)
.with_any_ci_minutes_used
.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current) .update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
end end
......
...@@ -85,6 +85,17 @@ RSpec.describe Ci::Minutes::BatchResetService do ...@@ -85,6 +85,17 @@ RSpec.describe Ci::Minutes::BatchResetService do
expect(namespace.last_ci_minutes_usage_notification_level).to be_nil expect(namespace.last_ci_minutes_usage_notification_level).to be_nil
end end
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 end
context 'when ID range is not provided' do context 'when ID range is not provided' do
...@@ -110,6 +121,17 @@ RSpec.describe Ci::Minutes::BatchResetService 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_notification_at).to be_nil
expect(namespace_6.last_ci_minutes_usage_notification_level).to be_nil expect(namespace_6.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, namespace_6.reload
].map(&:shared_runners_seconds_last_reset)
).to all(be_within(1.second).of(Time.current))
end
end end
context 'when an ActiveRecordError is raised' do 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