Commit 244fb0d9 authored by Mark Chao's avatar Mark Chao

Fix subscription seats update

Skip those without namespace and report to sentry
parent f2982a31
---
title: Fix max seats used not updated in billing summary
merge_request: 42184
author:
type: fixed
......@@ -16,6 +16,11 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
tuples = []
subscriptions.each do |subscription|
unless subscription.namespace
track_error(subscription)
next
end
subscription.refresh_seat_attributes!
tuples << [subscription.id, subscription.max_seats_used, subscription.seats_in_use, subscription.seats_owed]
......@@ -33,4 +38,14 @@ class UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker # rubocop:disable Scalab
end
end
end
private
def track_error(subscription)
Gitlab::ErrorTracking.track_exception(
StandardError.new('Namespace absent'),
gitlab_subscription_id: subscription.id,
namespace_id: subscription.namespace_id
)
end
end
......@@ -103,6 +103,28 @@ RSpec.describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker do
.and change(gitlab_subscription_2, :seats_in_use).from(0).to(13)
.and change(gitlab_subscription_2, :seats_owed).from(0).to(12)
end
context 'when namespace is absent' do
before do
gitlab_subscription.update!(namespace_id: nil)
end
it 'skips the subscription' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(StandardError),
{ gitlab_subscription_id: gitlab_subscription.id, namespace_id: nil }
)
expect do
perform_and_reload
end.to not_change(gitlab_subscription, :max_seats_used).from(0)
.and not_change(gitlab_subscription, :seats_in_use).from(0)
.and not_change(gitlab_subscription, :seats_owed).from(0)
.and change(gitlab_subscription_2, :max_seats_used).from(0).to(14)
.and change(gitlab_subscription_2, :seats_in_use).from(0).to(13)
.and change(gitlab_subscription_2, :seats_owed).from(0).to(12)
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