Skip to content

Commit

Permalink
feat(async-flow): check wake is called on upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Oct 3, 2024
1 parent 8ae8d08 commit d739b34
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/async-flow/src/async-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ const AdminAsyncFlowI = M.interface('AsyncFlowAdmin', {
getFlowForOutcomeVow: M.call(VowShape).returns(M.opt(M.remotable('flow'))),
});

/**
* Helper to enforce that a user "finalize" step has been called after an
* upgrade. In the first incarnation, the state is assumed to be born already
* finalized, and there is no failure if the "finalize" is not explicitly
* performed. In future incarnation the upgrade will fail if the "finalize" step
* is not explicitly performed.
*
* @param {Zone} outerZone
* @param {string} gateName
*/
const makeFinalizeUpgradeGate = (outerZone, gateName) => {
let finalized = false;

const finalize = () => {
if (finalized) return;

// Use an exo definition to leverage requirement to reconnect
// durable kinds on upgrades
outerZone.exo(`${gateName}Sentinel`, undefined, {});
finalized = true;
};
outerZone.makeOnce(`${gateName}Setup`, () => {
finalize();
return true;
});
return finalize;
};

/**
* @param {Zone} outerZone
* @param {PreparationOptions} [outerOptions]
Expand Down Expand Up @@ -503,11 +531,14 @@ export const prepareAsyncFlowTools = (outerZone, outerOptions = {}) => {
return harden(wrapperFunc);
};

const wakeUpgradeGate = makeFinalizeUpgradeGate(outerZone, 'WakeGate');

const adminAsyncFlow = outerZone.exo('AdminAsyncFlow', AdminAsyncFlowI, {
getFailures() {
return failures.snapshot();
},
wakeAll() {
wakeUpgradeGate();
// [...stuff.keys()] in order to snapshot before iterating
const failuresToRestart = [...failures.keys()];
const flowsToWake = [...eagerWakers.keys()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Generated by [AVA](https://avajs.dev).
FunctionUnwrapper_singleton: 'Alleged: FunctionUnwrapper',
LogStore_kindHandle: 'Alleged: kind',
StateUnwrapper_kindHandle: 'Alleged: kind',
WakeGateSentinel_kindHandle: 'Alleged: kind',
WakeGateSentinel_singleton: 'Alleged: WakeGateSentinel',
WakeGateSetup: true,
asyncFuncEagerWakers: [
Object @Alleged: asyncFlow flow {},
],
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Generated by [AVA](https://avajs.dev).
FunctionUnwrapper_singleton: 'Alleged: FunctionUnwrapper',
LogStore_kindHandle: 'Alleged: kind',
StateUnwrapper_kindHandle: 'Alleged: kind',
WakeGateSentinel_kindHandle: 'Alleged: kind',
WakeGateSentinel_singleton: 'Alleged: WakeGateSentinel',
WakeGateSetup: true,
asyncFuncEagerWakers: [],
asyncFuncFailures: {},
flowForOutcomeVow: {},
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Generated by [AVA](https://avajs.dev).
FunctionUnwrapper_singleton: 'Alleged: FunctionUnwrapper',
LogStore_kindHandle: 'Alleged: kind',
StateUnwrapper_kindHandle: 'Alleged: kind',
WakeGateSentinel_kindHandle: 'Alleged: kind',
WakeGateSentinel_singleton: 'Alleged: WakeGateSentinel',
WakeGateSetup: true,
asyncFuncEagerWakers: [],
asyncFuncFailures: {},
flowForOutcomeVow: {},
Expand Down
Binary file not shown.

0 comments on commit d739b34

Please sign in to comment.