Skip to content

Commit

Permalink
PAS-552 | Restore UserCountUpdaterBackgroundService for internal repo…
Browse files Browse the repository at this point in the history
…rting
  • Loading branch information
jonashendrickx committed Aug 4, 2024
1 parent fc9dcbd commit a0727c5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Passwordless.AdminConsole.Services;
using Passwordless.Common.Background;

namespace Passwordless.AdminConsole.Billing.BackgroundServices;

/// <summary>
/// Responsible for retrieving the current user count from the Passwordless API and storing it in the Admin Console.
/// It is only required for Bitwarden's internal reporting.
/// </summary>
public sealed class UserCountUpdaterBackgroundService(
IServiceProvider serviceProvider,
TimeProvider timeProvider,
ILogger<UserCountUpdaterBackgroundService> logger)
: BaseDelayedPeriodicBackgroundService(
new TimeOnly(0, 0),
TimeSpan.FromDays(1),
timeProvider,
logger)
{
protected override async Task DoWorkAsync(CancellationToken cancellationToken)
{
try
{
using IServiceScope scope = serviceProvider.CreateScope();
var usageService = scope.ServiceProvider.GetRequiredService<IUsageService>();
await usageService.UpdateUsersCountAsync();
}
catch (Exception e)
{
logger.LogCritical(e, $"{nameof(UserCountUpdaterBackgroundService)} failed.");
}
}
}
1 change: 1 addition & 0 deletions src/AdminConsole/Billing/BillingBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static void AddBilling(this WebApplicationBuilder builder)
builder.Services.AddHostedService<StripeConfigurationUpdaterBackgroundService>();
builder.Services.AddScoped<ISharedBillingService, SharedStripeBillingService>();
builder.Services.AddHostedService<MeteredBillingBackgroundService>();
builder.Services.AddHostedService<UserCountUpdaterBackgroundService>();
}
}
}

0 comments on commit a0727c5

Please sign in to comment.