Skip to content

Commit

Permalink
Skip providers that have no clients during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
amorask-bitwarden committed Oct 18, 2024
1 parent 4fec7ca commit 4597afd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
19 changes: 8 additions & 11 deletions src/Core/Billing/Migration/Models/ProviderMigrationTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
public enum ProviderMigrationProgress
{
Started = 1,
ClientsMigrated = 2,
TeamsPlanConfigured = 3,
EnterprisePlanConfigured = 4,
CustomerSetup = 5,
SubscriptionSetup = 6,
CreditApplied = 7,
Completed = 8,

Reversing = 9,
ReversedClientMigrations = 10,
RemovedProviderPlans = 11
NoClients = 2,
ClientsMigrated = 3,
TeamsPlanConfigured = 4,
EnterprisePlanConfigured = 5,
CustomerSetup = 6,
SubscriptionSetup = 7,
CreditApplied = 8,
Completed = 9,
}

public class ProviderMigrationTracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ public async Task Migrate(Guid providerId)

await migrationTrackerCache.StartTracker(provider);

await MigrateClientsAsync(providerId);
var organizations = await GetEnabledClientsAsync(provider.Id);

if (organizations.Count == 0)
{
logger.LogInformation("CB: Skipping migration for provider ({ProviderID}) with no clients", providerId);

await migrationTrackerCache.UpdateTrackingStatus(providerId, ProviderMigrationProgress.NoClients);

return;
}

await MigrateClientsAsync(providerId, organizations);

await ConfigureTeamsPlanAsync(providerId);

Expand All @@ -65,6 +76,16 @@ public async Task<ProviderMigrationResult> GetResult(Guid providerId)
return null;
}

if (providerTracker.Progress == ProviderMigrationProgress.NoClients)
{
return new ProviderMigrationResult
{
ProviderId = providerTracker.ProviderId,
ProviderName = providerTracker.ProviderName,
Result = providerTracker.Progress.ToString()
};
}

var clientTrackers = await Task.WhenAll(providerTracker.OrganizationIds.Select(organizationId =>
migrationTrackerCache.GetTracker(providerId, organizationId)));

Expand Down Expand Up @@ -99,12 +120,10 @@ public async Task<ProviderMigrationResult> GetResult(Guid providerId)

#region Steps

private async Task MigrateClientsAsync(Guid providerId)
private async Task MigrateClientsAsync(Guid providerId, List<Organization> organizations)
{
logger.LogInformation("CB: Migrating clients for provider ({ProviderID})", providerId);

var organizations = await GetEnabledClientsAsync(providerId);

var organizationIds = organizations.Select(organization => organization.Id);

await migrationTrackerCache.SetOrganizationIds(providerId, organizationIds);
Expand Down

0 comments on commit 4597afd

Please sign in to comment.