feat: Refresh billable user counts on SM license creation
What does this MR do and why?
When a new self-managed license is applied, the billable user counts (Users in subscription, Billable users, Maximum users, Users over subscription) are not updated until the next scheduled background job runs, which can be up to 24 hours later. This means admins see stale user counts after applying a new license.
This MR adds an after_create callback to the License model that enqueues Analytics::UsageTrends::CounterJobWorker immediately after a license is created, but only when the license has already started (i.e., starts_at <= Date.current). Future-dated licenses are skipped since the counts would not be relevant until the license becomes active.
References
- Closes #426797 (closed)
- Related to #370026 (closed)
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
-
In a rails console, check the current billable user count:
License.current.daily_billable_users_count -
Purchase a premium/ultimate subscription and apply the new activation code via the Admin UI
admin/subscription. -
Observe that
Analytics::UsageTrends::CounterJobWorkeris enqueued immediately. -
After the job completes, verify the user counts are updated in the Admin UI under Admin > Subscription.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

