Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: Allow execute steps to contribute success or fail items for display in the activity log #1766

Merged
merged 20 commits into from
Aug 12, 2024

Conversation

MicroFish91
Copy link
Contributor

@MicroFish91 MicroFish91 commented Aug 7, 2024

This implementation will enable execute steps to contribute success or fail items (as activity children) to the activity log upon execution. The resulting ExecuteActivityOutput will be handled by the Azure Wizard which has been updated accordingly.

Example of what this would look like in the activity log:

Example with continueOnFail set to true when a step fails:
image

Example of how it will probably look implemented in ACA:
microsoft/vscode-azurecontainerapps#722

Comment on lines +190 to 211
if (!step.shouldExecute(this._context)) {
step = steps.pop();
continue;
}

let output: types.ExecuteActivityOutput | undefined;
try {
this._context.telemetry.properties.lastStep = `execute-${getEffectiveStepId(step)}`;
await step.execute(this._context, internalProgress);
output = step.createSuccessOutput?.(this._context);
} catch (e) {
output = step.createFailOutput?.(this._context);
if (!step.options.continueOnFail) {
throw e;
}
} finally {
output ??= {};
this.displayActivityOutput(output, step.options);

currentStep += 1;
step = steps.pop();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the changes made here a bit? I just want to make sure we understand them fully before making changes to the wizard since it's so central to so many commands.

Copy link
Contributor Author

@MicroFish91 MicroFish91 Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, so basically all execute steps can now have the following optional methods: createFailOutput & createSuccessOutput. The output return signature for these methods is basically just an object with two properties: message?: string and item?: AzExtTreeItem (the tree item will be pushed in as an activity child). These outputs indicate what needs to be displayed to the user upon successful or unsuccessful execution of an execute step. If these optional methods are not defined on the step, then there should be no real difference to how our wizard steps currently run.

Success flow:

  • In the try block, assuming the step executes without throwing an error
  • (Line 199) We try to get an output from the step (optional since the method may not exist). Output will either be the defined success output or undefined if not set.
  • (Line 207) If initial return was undefined, output will be an empty object and displayActivityOutput will display nothing to the user.
  • (Line 207) If defined, displayActivityOutput will display any defined output message to the output log, and push the tree item into the activityChildren array if one exists on the context. If any options to suppress showing are set on the execute step, these will be honored here.

Fail flow:

  • In the try block, assuming the step executes and throws an error
  • (Line 201) We try to get an output from the step (optional since the method may not exist). Output will be either the defined fail output or undefined if not set.
  • (Line 202) New step option allows for us to essentially swallow errors. In some cases, we don't necessarily want the entire wizard to stop just because a step failed. So when a step has continueOnFail set, don't throw the error, but still display any defined output unless it has been explicitly set to be suppressed in the step options.
  • (Line 207) If initial value was undefined, output will be an empty object and displayActivityOutput will display nothing to the user.
  • (Line 207) If defined, displayActivityOutput will display any defined output message to the output log, and push any tree item into the activityChildren array if it has been initialized. If any options to suppress showing are set on the execute step, these will be honored here.

Rest of the code should be basically the same. I did use a guard clause with the shouldExecute to try and remove some nesting since we were adding more try/catch blocks. Let me know if that makes sense / if you have any questions / suggestions!

@MicroFish91 MicroFish91 merged commit 76f11f4 into main Aug 12, 2024
4 checks passed
@MicroFish91 MicroFish91 deleted the mwf/execute-activity-output branch August 12, 2024 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants