diff --git a/grafana-plugin/src/state/rootBaseStore/index.ts b/grafana-plugin/src/state/rootBaseStore/index.ts index 76d20346..6acd40ed 100644 --- a/grafana-plugin/src/state/rootBaseStore/index.ts +++ b/grafana-plugin/src/state/rootBaseStore/index.ts @@ -125,10 +125,10 @@ export class RootBaseStore { }; await retryFailingPromises([ - this.userStore.loadCurrentUser, - this.organizationStore.loadCurrentOrganization, - this.grafanaTeamStore.updateItems, - updateFeatures, + () => this.userStore.loadCurrentUser(), + () => this.organizationStore.loadCurrentOrganization(), + () => this.grafanaTeamStore.updateItems(), + () => updateFeatures(), ]); this.isBasicDataLoaded = true; } diff --git a/grafana-plugin/src/utils/async.test.ts b/grafana-plugin/src/utils/async.test.ts index 5c943f66..289ecfc6 100644 --- a/grafana-plugin/src/utils/async.test.ts +++ b/grafana-plugin/src/utils/async.test.ts @@ -8,7 +8,10 @@ describe('retryFailingPromises', () => { let attempts1 = 0; let attempts2 = 0; let attempts3 = 0; - const fetch1 = async () => Promise.resolve(++attempts1); + const fetch1 = (param = 'param') => { + ++attempts1; + return Promise.resolve(param); + }; const fetch2 = async () => Promise.reject(++attempts2); const fetch3 = async () => new Promise((resolve, reject) => { @@ -19,13 +22,16 @@ describe('retryFailingPromises', () => { reject(attempts3); }); - const result = await retryFailingPromises([fetch1, fetch2, fetch3], { maxAttempts: MAX_ATTEMPTS, delayInMs: 50 }); + const result = await retryFailingPromises([() => fetch1(), fetch2, fetch3], { + maxAttempts: MAX_ATTEMPTS, + delayInMs: 50, + }); expect(attempts1).toBe(1); expect(attempts2).toBe(MAX_ATTEMPTS); expect(attempts3).toBe(2); expect(result).toEqual([ - { status: 'fulfilled', value: 1 }, + { status: 'fulfilled', value: 'param' }, { status: 'rejected', reason: 5 }, { status: 'fulfilled', value: 2 }, ]); diff --git a/grafana-plugin/src/utils/async.ts b/grafana-plugin/src/utils/async.ts index 0ebafde1..ad6a3c10 100644 --- a/grafana-plugin/src/utils/async.ts +++ b/grafana-plugin/src/utils/async.ts @@ -1,7 +1,7 @@ -import { retry } from '@lifeomic/attempt'; +import { AttemptContext, retry } from '@lifeomic/attempt'; export const retryFailingPromises = async ( - asyncActions: Array<() => Promise>, + asyncActions: Array<(ctx?: AttemptContext) => Promise>, { maxAttempts = 3, delayInMs = 500 }: { maxAttempts?: number; delayInMs?: number } = {} ) => maxAttempts === 0