Skip to content

Commit

Permalink
ESD-29308: Add a 4s sleep on trigger update (#809)
Browse files Browse the repository at this point in the history
* Add a 4s sleep on trigger update

* Abstracting-out sleep function into utils, taking sleep out of loop

---------

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
sergiught and willvedd authored Jul 6, 2023
1 parent 19b9d3d commit 8e74bff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/tools/auth0/handlers/actions.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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') || {};

Expand Down
5 changes: 4 additions & 1 deletion src/tools/auth0/handlers/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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) => ({
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,7 @@ export const detectInsufficientScopeError = async <T>(
throw err;
}
};

export function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

0 comments on commit 8e74bff

Please sign in to comment.