diff --git a/src/tools/auth0/handlers/actions.ts b/src/tools/auth0/handlers/actions.ts index d279f45ce..a95e01a1a 100644 --- a/src/tools/auth0/handlers/actions.ts +++ b/src/tools/auth0/handlers/actions.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import DefaultAPIHandler, { order } from './default'; import log from '../../../logger'; -import { areArraysEquals } from '../../utils'; +import { areArraysEquals, sleep } from '../../utils'; import { Asset, Assets, CalculatedChanges } from '../../../types'; const MAX_ACTION_DEPLOY_RETRY_ATTEMPTS = 60; // 60 * 2s => 2 min timeout @@ -81,10 +81,6 @@ export const schema = { }, }; -function sleep(ms) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - function isActionsDisabled(err) { const errorBody = _.get(err, 'originalError.response.body') || {}; diff --git a/src/tools/auth0/handlers/triggers.ts b/src/tools/auth0/handlers/triggers.ts index ae35dde8d..55f84c160 100644 --- a/src/tools/auth0/handlers/triggers.ts +++ b/src/tools/auth0/handlers/triggers.ts @@ -3,6 +3,7 @@ import DefaultHandler, { order } from './default'; import constants from '../../constants'; import log from '../../../logger'; import { Assets } from '../../../types'; +import { sleep } from '../../utils'; export const schema = { type: 'object', @@ -96,7 +97,8 @@ export default class TriggersHandler extends DefaultHandler { // Do nothing if not set if (!triggers) return; - // Process each trigger + await sleep(2000); // Delay to allow newly-deployed actions to register in backend + await Promise.all( Object.entries(triggers).map(async ([name, data]) => { const bindings = data.map((binding) => ({ @@ -106,6 +108,7 @@ export default class TriggersHandler extends DefaultHandler { }, display_name: binding.display_name, })); + await this.client.actions.updateTriggerBindings({ trigger_id: name }, { bindings }); this.didUpdate({ trigger_id: name }); this.updated += 1; diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 81ace9dc3..3e6ea1c57 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -266,3 +266,7 @@ export const detectInsufficientScopeError = async ( throw err; } }; + +export function sleep(ms: number): Promise { + return new Promise((resolve) => setTimeout(resolve, ms)); +}