Skip to content

Commit

Permalink
Add check for decodedPayload strings to set metadata, add abort signa…
Browse files Browse the repository at this point in the history
…l on workflow metadata query, use italics in details
  • Loading branch information
Alex-Tideman committed Nov 20, 2024
1 parent 77f4828 commit 4d08dec
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/lib/components/lines-and-dots/workflow-detail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,44 @@
<Icon name={icon} />
{/if}
{#if title}
{title}
<i>{title}</i>
{/if}
{#if href}
<Link
{href}
class="flex w-fit flex-row items-center gap-1 truncate rounded-sm p-1 leading-4 {badge &&
'surface-subtle'}"
><span class="truncate font-bold">{content}</span>
><span class="truncate">{content}</span>
{#if filterable}
<Icon name="filter" class="shrink-0" />
{/if}
</Link>
{:else}
<Tooltip text={tooltip} hide={!tooltip} top>
<span
class="w-fit select-all truncate rounded-sm p-1 font-bold leading-4"
class="w-fit select-all truncate rounded-sm p-1 leading-4"
class:surface-subtle={badge}>{content}</span
>
</Tooltip>
{/if}
</Copyable>
{:else}
{#if title}
{title}
<i>{title}</i>
{/if}
{#if icon}
<Icon name={icon} />
{/if}
{#if href}
<Link
{href}
class="value truncate rounded-sm p-1 font-bold leading-4 {badge &&
class="value truncate rounded-sm p-1 leading-4 {badge &&
'surface-subtle'}">{content}</Link
>
{:else}
<Tooltip text={tooltip} hide={!tooltip} top>
<span
class="w-fit select-all truncate rounded-sm p-1 font-bold leading-4"
class="w-fit select-all truncate rounded-sm p-1 leading-4"
class:surface-subtle={badge}>{content}</span
>
</Tooltip>
Expand Down
28 changes: 18 additions & 10 deletions src/lib/layouts/workflow-run-layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
$: fullJson = { ...$workflowRun, eventHistory: $fullEventHistory };
let workflowError: NetworkError;
let eventHistoryController: AbortController;
let workflowRunController: AbortController;
let refreshInterval;
const { copy, copied } = copyToClipboard();
Expand All @@ -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);
Expand Down Expand Up @@ -98,6 +105,7 @@
$authUser?.accessToken,
);
workflowRunController = new AbortController();
getWorkflowMetadata(
{
namespace,
Expand All @@ -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,
});
};
Expand Down Expand Up @@ -149,8 +157,8 @@
const abortPolling = () => {
$fullEventHistory = [];
if (eventHistoryController) {
eventHistoryController.abort();
if (workflowRunController) {
workflowRunController.abort();
}
};
Expand Down
17 changes: 7 additions & 10 deletions src/lib/services/query-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryResponse> {
workflow = await workflow;
const parameters = await formatParameters(namespace, workflow, queryType);
Expand All @@ -78,9 +73,9 @@ async function fetchQuery(
queryArgs,
},
}),
signal,
},
request,
onError,
request: fetch,
notifyOnError: false,
});
}
Expand All @@ -89,12 +84,14 @@ export async function getWorkflowMetadata(
options: WorkflowParameters,
settings: Settings,
accessToken: string,
signal?: AbortSignal,
): Promise<WorkflowMetadata> {
try {
const metadata = await getQuery(
{ ...options, queryType: '__temporal_workflow_metadata' },
settings,
accessToken,
signal,
);
return metadata;
} catch (e) {
Expand All @@ -117,9 +114,9 @@ export async function getQuery(
options: QueryRequestParameters,
settings: Settings,
accessToken: string,
request = fetch,
signal?: AbortSignal,
): Promise<ParsedQuery> {
return fetchQuery(options, request).then(async (execution) => {
return fetchQuery(options, signal).then(async (execution) => {
const { queryResult } = execution ?? { queryResult: { payloads: [] } };

let data: ParsedQuery = queryResult.payloads;
Expand Down
14 changes: 12 additions & 2 deletions src/lib/services/workflow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utilities/decode-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ const keyIs = (key: string, ...validKeys: string[]) => {
export const decodeSingleReadablePayloadWithCodec = async (
payload: RawPayload | Payload,
settings: Settings = get(page).data.settings,
): Promise<string> => {
): Promise<string | Payload> => {
try {
const decode = decodeReadablePayloads(settings);
const data = await decode([payload]);
const result = data[0] as string;
const result = data[0];
return result || '';
} catch {
return '';
Expand Down
5 changes: 4 additions & 1 deletion src/routes/(app)/nexus/[id]/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4d08dec

Please sign in to comment.