1
0
mirror of https://github.com/bitwarden/server synced 2026-01-08 03:23:20 +00:00

[PM-20452] - Offloading Stripe Update (#6034)

* Adding job to update stripe subscriptions and increment seat count  when inviting a user.

* Updating name

* Added ef migrations

* Fixing script

* Fixing procedures. Added repo tests.

* Fixed set stored procedure. Fixed parameter name.

* Added tests for database calls and updated stored procedures

* Fixed build for sql file.

* fixing sproc

* File is nullsafe

* Adding view to select from instead of table.

* Updating UpdateSubscriptionStatus to use a CTE and do all the updates in 1 statement.

* Setting revision date when incrementing seat count

* Added feature flag check for the background job.

* Fixing nullable property.

* Removing new table and just adding the column to org. Updating to query and command. Updated tests.

* Adding migration script rename

* Add SyncSeats to Org.sql def

* Adding contraint name

* Removing old table files.

* Added tests

* Upped the frequency to be at the top of every 3rd hour.

* Updating error message.

* Removing extension method

* Changed to GuidIdArray

* Added xml doc and switched class to record
This commit is contained in:
Jared McCannon
2025-07-31 07:54:51 -05:00
committed by GitHub
parent 88dd977848
commit 86ce3a86e9
38 changed files with 10968 additions and 43 deletions

View File

@@ -0,0 +1,35 @@
using System.Collections.Immutable;
using Bit.Core;
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
using Bit.Core.Jobs;
using Bit.Core.Services;
using Quartz;
namespace Bit.Api.AdminConsole.Jobs;
public class OrganizationSubscriptionUpdateJob(ILogger<OrganizationSubscriptionUpdateJob> logger,
IGetOrganizationSubscriptionsToUpdateQuery query,
IUpdateOrganizationSubscriptionCommand command,
IFeatureService featureService) : BaseJob(logger)
{
protected override async Task ExecuteJobAsync(IJobExecutionContext _)
{
if (!featureService.IsEnabled(FeatureFlagKeys.ScimInviteUserOptimization))
{
return;
}
logger.LogInformation("OrganizationSubscriptionUpdateJob - START");
var organizationSubscriptionsToUpdate =
(await query.GetOrganizationSubscriptionsToUpdateAsync())
.ToImmutableList();
logger.LogInformation("OrganizationSubscriptionUpdateJob - {numberOfOrganizations} organization(s) to update",
organizationSubscriptionsToUpdate.Count);
await command.UpdateOrganizationSubscriptionAsync(organizationSubscriptionsToUpdate);
logger.LogInformation("OrganizationSubscriptionUpdateJob - COMPLETED");
}
}

View File

@@ -1,4 +1,5 @@
using Bit.Api.Auth.Jobs;
using Bit.Api.AdminConsole.Jobs;
using Bit.Api.Auth.Jobs;
using Bit.Core.Jobs;
using Bit.Core.Settings;
using Quartz;
@@ -65,6 +66,11 @@ public class JobsHostedService : BaseJobsHostedService
.WithIntervalInHours(24)
.RepeatForever())
.Build();
var updateOrgSubscriptionsTrigger = TriggerBuilder.Create()
.WithIdentity("UpdateOrgSubscriptionsTrigger")
.StartNow()
.WithCronSchedule("0 0 */3 * * ?") // top of every 3rd hour
.Build();
var jobs = new List<Tuple<Type, ITrigger>>
@@ -76,6 +82,7 @@ public class JobsHostedService : BaseJobsHostedService
new Tuple<Type, ITrigger>(typeof(ValidateOrganizationsJob), everyTwelfthHourAndThirtyMinutesTrigger),
new Tuple<Type, ITrigger>(typeof(ValidateOrganizationDomainJob), validateOrganizationDomainTrigger),
new Tuple<Type, ITrigger>(typeof(UpdatePhishingDomainsJob), updatePhishingDomainsTrigger),
new (typeof(OrganizationSubscriptionUpdateJob), updateOrgSubscriptionsTrigger),
};
if (_globalSettings.SelfHosted && _globalSettings.EnableCloudCommunication)
@@ -105,6 +112,7 @@ public class JobsHostedService : BaseJobsHostedService
services.AddTransient<ValidateOrganizationsJob>();
services.AddTransient<ValidateOrganizationDomainJob>();
services.AddTransient<UpdatePhishingDomainsJob>();
services.AddTransient<OrganizationSubscriptionUpdateJob>();
}
public static void AddCommercialSecretsManagerJobServices(IServiceCollection services)