From 4d08decb16554254b359c1fd7d9ce24b81a25702 Mon Sep 17 00:00:00 2001 From: Alex Tideman Date: Wed, 20 Nov 2024 08:57:52 -0600 Subject: [PATCH] Add check for decodedPayload strings to set metadata, add abort signal on workflow metadata query, use italics in details --- .../lines-and-dots/workflow-detail.svelte | 12 ++++---- src/lib/layouts/workflow-run-layout.svelte | 28 ++++++++++++------- src/lib/services/query-service.ts | 17 +++++------ src/lib/services/workflow-service.ts | 14 ++++++++-- src/lib/utilities/decode-payload.ts | 4 +-- src/routes/(app)/nexus/[id]/+layout.ts | 5 +++- 6 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/lib/components/lines-and-dots/workflow-detail.svelte b/src/lib/components/lines-and-dots/workflow-detail.svelte index 30b26379e..08e25d0a2 100644 --- a/src/lib/components/lines-and-dots/workflow-detail.svelte +++ b/src/lib/components/lines-and-dots/workflow-detail.svelte @@ -29,14 +29,14 @@ {/if} {#if title} - {title} + {title} {/if} {#if href} {content} + >{content} {#if filterable} {/if} @@ -44,7 +44,7 @@ {:else} {content} @@ -52,7 +52,7 @@ {:else} {#if title} - {title} + {title} {/if} {#if icon} @@ -60,13 +60,13 @@ {#if href} {content} {:else} {content} diff --git a/src/lib/layouts/workflow-run-layout.svelte b/src/lib/layouts/workflow-run-layout.svelte index c34c04339..18d5e91c0 100644 --- a/src/lib/layouts/workflow-run-layout.svelte +++ b/src/lib/layouts/workflow-run-layout.svelte @@ -42,7 +42,7 @@ $: fullJson = { ...$workflowRun, eventHistory: $fullEventHistory }; let workflowError: NetworkError; - let eventHistoryController: AbortController; + let workflowRunController: AbortController; let refreshInterval; const { copy, copied } = copyToClipboard(); @@ -54,13 +54,20 @@ const decodeUserMetadata = async (workflow: WorkflowExecution) => { try { if (workflow?.summary) { - $workflowRun.userMetadata.summary = - await decodeSingleReadablePayloadWithCodec(workflow.summary); + const decodedSummary = await decodeSingleReadablePayloadWithCodec( + workflow.summary, + ); + if (typeof decodedSummary === 'string') { + $workflowRun.userMetadata.summary = decodedSummary; + } } - if (workflow?.details) { - $workflowRun.userMetadata.details = - await decodeSingleReadablePayloadWithCodec(workflow.details); + const decodedDetails = await decodeSingleReadablePayloadWithCodec( + workflow.details, + ); + if (typeof decodedDetails === 'string') { + $workflowRun.userMetadata.details = decodedDetails; + } } } catch (e) { console.error('Error decoding user metadata', e); @@ -98,6 +105,7 @@ $authUser?.accessToken, ); + workflowRunController = new AbortController(); getWorkflowMetadata( { namespace, @@ -108,17 +116,17 @@ }, settings, $authUser?.accessToken, + workflowRunController.signal, ).then((metadata) => { $workflowRun.metadata = metadata; }); - eventHistoryController = new AbortController(); $fullEventHistory = await fetchAllEvents({ namespace, workflowId, runId, sort: 'ascending', - signal: eventHistoryController.signal, + signal: workflowRunController.signal, historySize: workflow.historyEvents, }); }; @@ -149,8 +157,8 @@ const abortPolling = () => { $fullEventHistory = []; - if (eventHistoryController) { - eventHistoryController.abort(); + if (workflowRunController) { + workflowRunController.abort(); } }; diff --git a/src/lib/services/query-service.ts b/src/lib/services/query-service.ts index 59a1407bb..3fe569f28 100644 --- a/src/lib/services/query-service.ts +++ b/src/lib/services/query-service.ts @@ -54,12 +54,7 @@ const formatParameters = async ( async function fetchQuery( { workflow, namespace, queryType, queryArgs }: QueryRequestParameters, - request = fetch, - onError?: (error: { - status: number; - statusText: string; - body: unknown; - }) => void, + signal?: AbortSignal, ): Promise { workflow = await workflow; const parameters = await formatParameters(namespace, workflow, queryType); @@ -78,9 +73,9 @@ async function fetchQuery( queryArgs, }, }), + signal, }, - request, - onError, + request: fetch, notifyOnError: false, }); } @@ -89,12 +84,14 @@ export async function getWorkflowMetadata( options: WorkflowParameters, settings: Settings, accessToken: string, + signal?: AbortSignal, ): Promise { try { const metadata = await getQuery( { ...options, queryType: '__temporal_workflow_metadata' }, settings, accessToken, + signal, ); return metadata; } catch (e) { @@ -117,9 +114,9 @@ export async function getQuery( options: QueryRequestParameters, settings: Settings, accessToken: string, - request = fetch, + signal?: AbortSignal, ): Promise { - return fetchQuery(options, request).then(async (execution) => { + return fetchQuery(options, signal).then(async (execution) => { const { queryResult } = execution ?? { queryResult: { payloads: [] } }; let data: ParsedQuery = queryResult.payloads; diff --git a/src/lib/services/workflow-service.ts b/src/lib/services/workflow-service.ts index 4f1478955..f66d47e2a 100644 --- a/src/lib/services/workflow-service.ts +++ b/src/lib/services/workflow-service.ts @@ -633,12 +633,22 @@ export const fetchInitialValuesForStartWorkflow = async ({ let summary = ''; if (workflow.summary) { - summary = await decodeSingleReadablePayloadWithCodec(workflow.summary); + const decodedSummary = await decodeSingleReadablePayloadWithCodec( + workflow.summary, + ); + if (typeof decodedSummary === 'string') { + summary = decodedSummary; + } } let details = ''; if (workflow.details) { - details = await decodeSingleReadablePayloadWithCodec(workflow.details); + const decodedDetails = await decodeSingleReadablePayloadWithCodec( + workflow.summary, + ); + if (typeof decodedDetails === 'string') { + details = decodedDetails; + } } const input = stringifyWithBigInt(convertedAttributes?.payloads[0]); diff --git a/src/lib/utilities/decode-payload.ts b/src/lib/utilities/decode-payload.ts index a661b68ed..7b871ff29 100644 --- a/src/lib/utilities/decode-payload.ts +++ b/src/lib/utilities/decode-payload.ts @@ -179,11 +179,11 @@ const keyIs = (key: string, ...validKeys: string[]) => { export const decodeSingleReadablePayloadWithCodec = async ( payload: RawPayload | Payload, settings: Settings = get(page).data.settings, -): Promise => { +): Promise => { try { const decode = decodeReadablePayloads(settings); const data = await decode([payload]); - const result = data[0] as string; + const result = data[0]; return result || ''; } catch { return ''; diff --git a/src/routes/(app)/nexus/[id]/+layout.ts b/src/routes/(app)/nexus/[id]/+layout.ts index 6523eaee8..b33c2c060 100644 --- a/src/routes/(app)/nexus/[id]/+layout.ts +++ b/src/routes/(app)/nexus/[id]/+layout.ts @@ -15,7 +15,10 @@ export const load = async ({ params, fetch, parent }) => { endpoint.spec.description, data.settings, ); - description = decodedDescription; + + if (typeof decodedDescription === 'string') { + description = decodedDescription; + } } } catch (e) { console.error('Error decoding Nexus Endpoint description:', e);