Skip to content

Commit

Permalink
Merge pull request #902 from posit-dev/sagerb-cleanup-progress-events
Browse files Browse the repository at this point in the history
Cleanup progress events
  • Loading branch information
sagerb authored Jan 29, 2024
2 parents d2ec513 + 93e04d9 commit 27523c5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
27 changes: 24 additions & 3 deletions web/src/api/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface EventSubscriptionTargetCallbackMap {
'publish/createBundle/failure': OnPublishCreateBundleFailureCallback

'publish/createDeployment/start': OnPublishCreateDeploymentStartCallback
'publish/createDeployment/log': OnPublishCreateDeploymentLogCallback
'publish/createDeployment/success': OnPublishCreateDeploymentSuccessCallback
'publish/createDeployment/failure': OnPublishCreateDeploymentFailureCallback

Expand Down Expand Up @@ -316,7 +317,7 @@ export type OnPublishCreateNewDeploymentFailureCallback =
(msg: PublishCreateNewDeploymentFailure) => void;
export function isPublishCreateNewDeploymentFailure(arg: Events):
arg is PublishCreateNewDeploymentFailure {
return arg.type === 'publish/createDeployment/failure';
return arg.type === 'publish/createNewDeployment/failure';
}

export interface PublishSetEnvVarsStart extends EventStreamMessage {
Expand Down Expand Up @@ -420,11 +421,18 @@ export function isPublishCreateBundleFailure(arg: Events):
export interface PublishCreateDeploymentStart extends EventStreamMessage {
type: 'publish/createDeployment/start',
data: {
// "level": "INFO", "message": "Creating deployment", "localId": "O-6_TzmRRBWtd4rm"
// {
// "level": "INFO",
// "message": "Updating deployment settings",
// "contentId": "73078698-65d5-4839-9b42-a3ff32f7b25d",
// "localId": "ZGgbfUM6lLxh1VYN",
// "saveName": ""
// }
level: string,
message: string,
saveName: string,
contentId: string,
localId: string,
saveName: string,
}
}
export type OnPublishCreateDeploymentStartCallback = (msg: PublishCreateDeploymentStart) => void;
Expand All @@ -433,6 +441,19 @@ export function isPublishCreateDeploymentStart(arg: Events):
return arg.type === 'publish/createDeployment/start';
}

export interface PublishCreateDeploymentLog extends EventStreamMessage {
type: 'publish/createDeployment/log',
data: {
// structured data not guaranteed, use selective or generic queries
// from data map
}
}
export type OnPublishCreateDeploymentLogCallback = (msg: PublishCreateDeploymentLog) => void;
export function isPublishCreateDeploymentLog(arg: Events):
arg is PublishCreateDeploymentLog {
return arg.type === 'publish/createDeployment/log';
}

export interface PublishCreateDeploymentSuccess extends EventStreamMessage {
type: 'publish/createDeployment/success',
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<li>
{{ deployment.deploymentError.msg }}
</li>
<li>
<li v-if="scrubbedErrorData">
<ul>
<li
v-for="(value, name, index) in scrubbedErrorData"
Expand Down Expand Up @@ -91,6 +91,10 @@ const scrubbedErrorData = computed(() => {
...remainingData
} = props.deployment.deploymentError?.data as Record<string, string>;

if (Object.keys(remainingData).length === 0) {
return undefined;
}

return remainingData;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<li>
{{ deployment.error.msg }}
</li>
<li>
<li v-if="scrubbedErrorData">
<ul>
<li
v-for="(value, name, index) in scrubbedErrorData"
Expand Down Expand Up @@ -87,6 +87,10 @@ const scrubbedErrorData = computed(() => {
...remainingData
} = props.deployment.error?.data as Record<string, string>;

if (Object.keys(remainingData).length === 0) {
return undefined;
}

return remainingData;
});

Expand Down
12 changes: 12 additions & 0 deletions web/src/stores/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PublishCreateBundleSuccess,
PublishCreateBundleFailure,
PublishCreateDeploymentStart,
PublishCreateDeploymentLog,
PublishCreateDeploymentSuccess,
PublishCreateDeploymentFailure,
PublishUploadBundleStart,
Expand Down Expand Up @@ -499,6 +500,16 @@ export const useEventStore = defineStore('event', () => {
}
};

const onPublishCreateDeploymentLog = (msg: PublishCreateDeploymentLog) => {
const localId = getLocalId(msg);

if (currentPublishStatus.value.localId === localId) {
const publishStatus = currentPublishStatus.value.status;
publishStatus.steps.createDeployment.logs.push(msg);
publishStatus.steps.createDeployment.allMsgs.push(msg);
}
};

const onPublishCreateDeploymentSuccess = (msg: PublishCreateDeploymentSuccess) => {
const localId = getLocalId(msg);

Expand Down Expand Up @@ -816,6 +827,7 @@ export const useEventStore = defineStore('event', () => {

eventStream.addEventMonitorCallback('publish/createDeployment/start', onPublishCreateDeploymentStart);
eventStream.addEventMonitorCallback('publish/createDeployment/success', onPublishCreateDeploymentSuccess);
eventStream.addEventMonitorCallback('publish/createDeployment/log', onPublishCreateDeploymentLog);
eventStream.addEventMonitorCallback('publish/createDeployment/failure', onPublishCreateDeploymentFailure);

eventStream.addEventMonitorCallback('publish/setEnvVars/start', onPublishSetEnvVarsStart);
Expand Down
14 changes: 3 additions & 11 deletions web/src/views/deploy-progress/DeployStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,10 @@ import { PropType, computed } from 'vue';
import {
EventStreamMessage,
isErrorEventStreamMessage,
isPublishCheckCapabilitiesSuccess,
isPublishCreateBundleLog,
isPublishCreateBundleSuccess,
isPublishCreateDeploymentStart,
isPublishCreateDeploymentSuccess,
isPublishCreateNewDeploymentStart,
isPublishCreateNewDeploymentSuccess,
isPublishDeployBundleSuccess,
isPublishRestorePythonEnvLog,
isPublishRestorePythonEnvStart,
isPublishRestorePythonEnvStatus,
Expand All @@ -117,16 +113,12 @@ const shouldSkipMessage = (msg: EventStreamMessage): boolean => {
};

const formatMsg = (msg: EventStreamMessage): string => {
if (isPublishCreateNewDeploymentStart(msg) || isPublishCreateNewDeploymentSuccess(msg)) {
if (isPublishCreateNewDeploymentSuccess(msg)) {
return `${msg.data.message} ${msg.data.saveName}`;
} else if (isPublishCheckCapabilitiesSuccess(msg)) {
return `${msg.data.message} (${msg.data.status})`;
} else if (isPublishCreateBundleSuccess(msg)) {
return `${msg.data.message} ${msg.data.filename}`;
} else if (isPublishCreateDeploymentStart(msg) || isPublishCreateDeploymentSuccess(msg)) {
return `${msg.data.message} ${msg.data.saveName}`;
} else if (isPublishDeployBundleSuccess(msg)) {
return `${msg.data.message}, TaskID: ${msg.data.taskId}`;
} else if (isPublishCreateDeploymentStart(msg)) {
return `${msg.data.message}, ContentId: ${msg.data.contentId}`;
} else if (isPublishRestorePythonEnvStart(msg)) {
return `${msg.data.message}, Source: ${msg.data.source}`;
} else if (isPublishCreateBundleLog(msg)) {
Expand Down

0 comments on commit 27523c5

Please sign in to comment.