Commit ece44622 authored by Matija Čupić's avatar Matija Čupić

Feature flag resetting ci usage for all namespaces

parent 9c3b16b7
...@@ -18,6 +18,7 @@ class ProjectStatistics < ApplicationRecord ...@@ -18,6 +18,7 @@ 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,6 +6,7 @@ class NamespaceStatistics < ApplicationRecord ...@@ -6,6 +6,7 @@ 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
......
...@@ -80,13 +80,13 @@ module Ci ...@@ -80,13 +80,13 @@ module Ci
end end
def reset_shared_runners_seconds!(namespaces) def reset_shared_runners_seconds!(namespaces)
NamespaceStatistics namespace_relation = NamespaceStatistics.for_namespaces(namespaces)
.for_namespaces(namespaces) namespace_relation = namespace_relation.with_any_ci_minutes_used unless ::Gitlab::Ci::Features.reset_ci_minutes_for_all_namespaces?
.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current) namespace_relation.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
::ProjectStatistics project_relation = ::ProjectStatistics.for_namespaces(namespaces)
.for_namespaces(namespaces) project_relation = project_relation.with_any_ci_minutes_used unless ::Gitlab::Ci::Features.reset_ci_minutes_for_all_namespaces?
.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current) project_relation.update_all(shared_runners_seconds: 0, shared_runners_seconds_last_reset: Time.current)
end end
def reset_ci_minutes_notifications!(namespaces) def reset_ci_minutes_notifications!(namespaces)
......
...@@ -85,6 +85,10 @@ module Gitlab ...@@ -85,6 +85,10 @@ module Gitlab
def self.job_entry_matches_all_keys? def self.job_entry_matches_all_keys?
::Feature.enabled?(:ci_job_entry_matches_all_keys) ::Feature.enabled?(:ci_job_entry_matches_all_keys)
end end
def self.reset_ci_minutes_for_all_namespaces?
::Feature.enabled?(:reset_ci_minutes_for_all_namespaces, default_enabled: false)
end
end end
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