diff --git a/.changeset/green-jokes-burn.md b/.changeset/green-jokes-burn.md new file mode 100644 index 000000000..28c20767f --- /dev/null +++ b/.changeset/green-jokes-burn.md @@ -0,0 +1,5 @@ +--- +"app-avatax": patch +--- + +Run webhook migrations in parallel. diff --git a/apps/avatax/scripts/run-webhooks-migration.ts b/apps/avatax/scripts/run-webhooks-migration.ts index 6d32cf0d5..484153661 100644 --- a/apps/avatax/scripts/run-webhooks-migration.ts +++ b/apps/avatax/scripts/run-webhooks-migration.ts @@ -41,49 +41,51 @@ const runMigrations = async () => { process.exit(1); }); - for (const saleorEnv of saleorCloudEnv) { - const { saleorApiUrl, token } = saleorEnv; - - logger.info(`Migrating webhooks for ${saleorApiUrl}`); - - const client = createInstrumentedGraphqlClient({ - saleorApiUrl: saleorApiUrl, - token: token, - }); - - const runner = new WebhookMigrationRunner({ - dryRun, - logger, - client, - saleorApiUrl, - getManifests: async ({ appDetails }) => { - const webhooks = appDetails.webhooks; - - if (!webhooks?.length) { - logger.warn("The environment does not have any webhooks, skipping"); - return []; - } - - const enabled = webhooks.some((w) => w.isActive); - - const targetUrl = appDetails.appUrl; - - if (!targetUrl?.length) { - logger.error("App has no defined appUrl, skipping"); - return []; - } - - const baseUrl = new URL(targetUrl).origin; - - // All webhooks in this application are turned on or off. If any of them is enabled, we enable all of them. - return appWebhooks.map((w) => ({ ...w.getWebhookManifest(baseUrl), isActive: enabled })); - }, - }); - - await runner.migrate().catch((error) => { - Sentry.captureException(error); - }); - } + await Promise.allSettled( + saleorCloudEnv.map(async (saleorEnv) => { + const { saleorApiUrl, token } = saleorEnv; + + logger.info(`Migrating webhooks for ${saleorApiUrl}`); + + const client = createInstrumentedGraphqlClient({ + saleorApiUrl: saleorApiUrl, + token: token, + }); + + const runner = new WebhookMigrationRunner({ + dryRun, + logger, + client, + saleorApiUrl, + getManifests: async ({ appDetails }) => { + const webhooks = appDetails.webhooks; + + if (!webhooks?.length) { + logger.warn("The environment does not have any webhooks, skipping"); + return []; + } + + const enabled = webhooks.some((w) => w.isActive); + + const targetUrl = appDetails.appUrl; + + if (!targetUrl?.length) { + logger.error("App has no defined appUrl, skipping"); + return []; + } + + const baseUrl = new URL(targetUrl).origin; + + // All webhooks in this application are turned on or off. If any of them is enabled, we enable all of them. + return appWebhooks.map((w) => ({ ...w.getWebhookManifest(baseUrl), enabled })); + }, + }); + + await runner.migrate().catch((error) => { + Sentry.captureException(error); + }); + }), + ); }; runMigrations();