Commit 3590863b authored by Max Orefice's avatar Max Orefice Committed by Fabio Pitino

Update pending build when resetting monthly ci minutes

This commit makes sure to update our ci_pending_builds
when resetting monthly ci minutes.
parent d5dfee6a
......@@ -37,6 +37,7 @@ module Ci
new_usage.run_after_commit do
Namespace.find_by_id(namespace_id).try do |namespace|
Ci::Minutes::Limit.new(namespace).recalculate_remaining_purchased_minutes!
Ci::Minutes::RefreshCachedDataWorker.perform_async(namespace_id) # rubocop:disable CodeReuse/Worker
end
end
......
......@@ -768,6 +768,15 @@
:weight: 1
:idempotent:
:tags: []
- :name: pipeline_background:ci_minutes_refresh_cached_data
:worker_name: Ci::Minutes::RefreshCachedDataWorker
:feature_category: :continuous_integration
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: pipeline_background:ci_minutes_update_project_and_namespace_usage
:worker_name: Ci::Minutes::UpdateProjectAndNamespaceUsageWorker
:feature_category: :continuous_integration
......
# frozen_string_literal: true
module Ci
module Minutes
class RefreshCachedDataWorker
include ApplicationWorker
include PipelineBackgroundQueue
data_consistency :always
idempotent!
def perform(root_namespace_id)
::Namespace.find_by_id(root_namespace_id).try do |root_namespace|
::Ci::Minutes::RefreshCachedDataService.new(root_namespace).execute
end
end
end
end
end
......@@ -43,6 +43,14 @@ RSpec.describe Ci::Minutes::NamespaceMonthlyUsage do
expect(subject.created_at).to eq(Time.current)
end
end
it 'kicks off Ci::Minutes::RefreshCachedDataWorker' do
expect(::Ci::Minutes::RefreshCachedDataWorker)
.to receive(:perform_async)
.with(namespace.id)
subject
end
end
shared_examples 'does not update the additional minutes' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::Minutes::RefreshCachedDataWorker do
describe '#perform' do
context 'when namespace is out of CI minutes' do
include_examples 'an idempotent worker' do
let_it_be(:namespace) { create(:namespace, :with_used_build_minutes_limit) }
let_it_be_with_reload(:pending_build) { create(:ci_pending_build, minutes_exceeded: false, namespace: namespace) }
let(:job_args) { namespace.id }
it 'updates pending builds' do
subject
expect(pending_build.minutes_exceeded).to be_truthy
end
end
end
context 'when namespace has CI minutes' do
include_examples 'an idempotent worker' do
let_it_be(:namespace) { create(:namespace, :with_not_used_build_minutes_limit) }
let_it_be_with_reload(:pending_build) { create(:ci_pending_build, minutes_exceeded: true, namespace: namespace) }
let(:job_args) { namespace.id }
it 'updates pending builds' do
subject
expect(pending_build.minutes_exceeded).to be_falsey
end
end
end
context 'namespace does not exist' do
it 'does nothing' do
expect { described_class.new.perform(non_existing_record_id) }.not_to raise_error
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