Skip to content

Commit

Permalink
TASK: Implement Publishing Retry
Browse files Browse the repository at this point in the history
  • Loading branch information
grebaldi committed Mar 21, 2024
1 parent 4342e70 commit 6f73c45
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
14 changes: 14 additions & 0 deletions packages/neos-ui-redux-store/src/CR/Publishing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export enum actionTypes {
CANCELLED = '@neos/neos-ui/CR/Publishing/CANCELLED',
CONFIRMED = '@neos/neos-ui/CR/Publishing/CONFIRMED',
FAILED = '@neos/neos-ui/CR/Publishing/FAILED',
RETRIED = '@neos/neos-ui/CR/Publishing/RETRIED',
SUCEEDED = '@neos/neos-ui/CR/Publishing/SUCEEDED',
ACKNOWLEDGED = '@neos/neos-ui/CR/Publishing/ACKNOWLEDGED',
FINISHED = '@neos/neos-ui/CR/Publishing/FINISHED'
Expand Down Expand Up @@ -77,6 +78,11 @@ const confirm = () => createAction(actionTypes.CONFIRMED);
const fail = (error: null | AnyError) =>
createAction(actionTypes.FAILED, {error});

/**
* Attempt to retry a failed publish/discard workflow
*/
const retry = () => createAction(actionTypes.RETRIED);

/**
* Signal that the ongoing publish/discard workflow succeeded
*/
Expand All @@ -100,6 +106,7 @@ export const actions = {
cancel,
confirm,
fail,
retry,
succeed,
acknowledge,
finish
Expand Down Expand Up @@ -144,6 +151,13 @@ export const reducer = (state: State = defaultState, action: Action): State => {
error: action.payload.error
}
};
case actionTypes.RETRIED:
return {
...state,
process: {
phase: PublishingPhase.ONGOING
}
};
case actionTypes.SUCEEDED:
return {
...state,
Expand Down
49 changes: 33 additions & 16 deletions packages/neos-ui-sagas/src/Publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,30 @@ export function * watchPublishing({routes}) {
const ancestorId = yield select(ancestorIdSelector);
const publishableNodes = yield select(publishableNodesSelector);

let affectedNodes = [];
try {
const result = yield call(endpoint, ancestorId, workspaceName);

if ('success' in result) {
affectedNodes = publishableNodes;
yield put(actions.CR.Publishing.succeed());

if (mode === PublishingMode.DISCARD) {
yield * reloadAfterDiscard(publishableNodes, routes);
let affectedNodes = [];
do {
try {
const result = yield call(endpoint, ancestorId, workspaceName);

if ('success' in result) {
affectedNodes = publishableNodes;
yield put(actions.CR.Publishing.succeed());

if (mode === PublishingMode.DISCARD) {
yield * reloadAfterDiscard(publishableNodes, routes);
}
} else if ('error' in result) {
yield put(actions.CR.Publishing.fail(result.error));
} else {
yield put(actions.CR.Publishing.fail(null));
}
} else if ('error' in result) {
yield put(actions.CR.Publishing.fail(result.error));
} else {
yield put(actions.CR.Publishing.fail(null));
} catch (error) {
yield put(actions.CR.Publishing.fail(error));
}
} catch (error) {
yield put(actions.CR.Publishing.fail(error));
}
} while (yield * waitForRetry());

yield take(actionTypes.CR.Publishing.ACKNOWLEDGED);
yield put(actions.CR.Publishing.finish(affectedNodes));
});
}
Expand All @@ -86,6 +89,20 @@ function * waitForConfirmation() {
return false;
}

function * waitForRetry() {
const waitForNextAction = yield race([
take(actionTypes.CR.Publishing.ACKNOWLEDGED),
take(actionTypes.CR.Publishing.RETRIED)
]);
const [nextAction] = Object.values(waitForNextAction);

if (nextAction.type === actionTypes.CR.Publishing.RETRIED) {
return true;
}

return false;
}

function * reloadAfterDiscard(discardedNodes, routes) {
const currentContentCanvasContextPath = yield select(selectors.CR.Nodes.documentNodeContextPathSelector);
const currentDocumentParentLine = yield select(selectors.CR.Nodes.documentNodeParentLineSelector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type PublishingDialogProperties =
type PublishingDialogHandlers = {
cancel: () => void;
confirm: () => void;
retry: () => void;
acknowledge: () => void;
}

Expand All @@ -51,12 +52,12 @@ const PublishingDialog: React.FC<PublishingDialogProps> = (props) => {
const handleConfirm = React.useCallback(() => {
props.confirm();
}, []);
const handleRetry = React.useCallback(() => {
props.retry();
}, []);
const handleAcknowledge = React.useCallback(() => {
props.acknowledge();
}, []);
const handleRetry = React.useCallback(() => {
console.log('@TODO: handleRetry');
}, []);

if (props.publishingState === null) {
return null;
Expand Down Expand Up @@ -95,8 +96,8 @@ const PublishingDialog: React.FC<PublishingDialogProps> = (props) => {
scopeTitle={props.scopeTitle}
numberOfChanges={props.numberOfChanges}
result={props.publishingState.process}
onAcknowledge={handleAcknowledge}
onRetry={handleRetry}
onAcknowledge={handleAcknowledge}
/>
);
}
Expand Down Expand Up @@ -134,5 +135,6 @@ export default connect((state: GlobalState): PublishingDialogProperties => {
}, {
confirm: (actions as any).CR.Publishing.confirm,
cancel: (actions as any).CR.Publishing.cancel,
retry: (actions as any).CR.Publishing.retry,
acknowledge: (actions as any).CR.Publishing.acknowledge
})(PublishingDialog);
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export const ResultDialog: React.FC<{
scopeTitle: string;
numberOfChanges: number;
result: Result;
onAcknowledge: () => void;
onRetry: () => void;
onAcknowledge: () => void;
}> = (props) => {
const variant = ResultDialogVariants[props.mode];

Expand Down

0 comments on commit 6f73c45

Please sign in to comment.