-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAS-552 | Restore UserCountUpdaterBackgroundService for internal repo…
…rting
- Loading branch information
1 parent
fc9dcbd
commit a0727c5
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/AdminConsole/Billing/BackgroundServices/UserCountUpdaterBackgroundService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters