Recalculate additional CI minutes lazily on a monthly basis
Objectives
On the 1st of the month, recalculate the remaining purchased minutes based on the previous month's usage. This should occur when we lazily create new records for Ci::Minutes::NamespaceMonthlyUsage
.
Technical Approach
We currently recalculate remaining additional/purchased CI minutes in bulk. The logic is the same but needs to be done for the single namespace being lazily reset.
- If the minutes consumption is greater than the monthly limit (
ci_namespace_monthly_usage.amount_used > namespaces.shared_runners_minutes_limit
) (or default limit fromGitlab::CurrentSettings
) and namespace has any additional minutes available (namespaces.extra_shared_runners_minutes_limit > 0
) - Then, update
namespaces.extra_shared_runners_minutes_limit
as the difference between the minutes consumption minus the sum of monthly minutes limit and additional minutes. - Do that only if the feature flag
ci_use_new_monthly_minutes
is enabled, to avoid double reset ofextra_shared_runners_minutes_limit
- Skip the recalculation of
extra_shared_runners_minutes_limit
inCi::Minutes::BatchResetService
if the feature flagci_use_new_monthly_minutes
is enabled.
Edited by Fabio Pitino