From 4d2f52c815edeb4477f5ccb9cdfb68e881c494d1 Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Mon, 1 Apr 2024 14:12:02 -0500 Subject: [PATCH] make sure occurred is always set --- src/factories/eventData.ts | 7 +++---- src/factories/nodeFlowRun.ts | 16 +++++++--------- src/models/RunGraph.ts | 10 +++++----- src/objects/flowRunEvents.ts | 8 +++++++- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/factories/eventData.ts b/src/factories/eventData.ts index 69d05ae3..ffdf5ae4 100644 --- a/src/factories/eventData.ts +++ b/src/factories/eventData.ts @@ -1,5 +1,5 @@ import { MaybeRefOrGetter, toValue } from 'vue' -import { RunGraphEvent, RunGraphFetchEventsOptions } from '@/models' +import { RunGraphEvent, RunGraphFetchEventsContext } from '@/models' import { waitForConfig } from '@/objects/config' import { waitForRunData } from '@/objects/nodes' @@ -7,9 +7,8 @@ type EventDataCallback = (data: RunGraphEvent[]) => void // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export async function eventDataFactory( - runId: string, + context: MaybeRefOrGetter, callback: EventDataCallback, - options?: MaybeRefOrGetter, ) { const runGraphData = await waitForRunData() const config = await waitForConfig() @@ -19,7 +18,7 @@ export async function eventDataFactory( async function start(): Promise { try { - data = await config.fetchEvents(runId, toValue(options)) + data = await config.fetchEvents(toValue(context)) callback(data) } catch (error) { diff --git a/src/factories/nodeFlowRun.ts b/src/factories/nodeFlowRun.ts index 0917bb91..420fb942 100644 --- a/src/factories/nodeFlowRun.ts +++ b/src/factories/nodeFlowRun.ts @@ -20,7 +20,7 @@ import { runStatesFactory } from '@/factories/runStates' import { RunGraphArtifact, RunGraphEvent, RunGraphStateEvent } from '@/models' import { BoundsContainer } from '@/models/boundsContainer' import { NodeSize } from '@/models/layout' -import { RunGraphFetchEventsOptions, RunGraphNode } from '@/models/RunGraph' +import { RunGraphFetchEventsContext, RunGraphNode } from '@/models/RunGraph' import { waitForConfig } from '@/objects/config' import { cull } from '@/objects/culling' import { layout, waitForSettings } from '@/objects/settings' @@ -73,17 +73,15 @@ export async function flowRunContainerFactory(node: RunGraphNode) { renderBorder() }) - function getEventFactoryOptions(): RunGraphFetchEventsOptions { - return { - since: internalNode.start_time, - until: internalNode.end_time ?? new Date(), - } - } - const { start: startEventsData, stop: stopEventsData } = await eventDataFactory(internalNode.id, data => { + const { start: startEventsData, stop: stopEventsData } = await eventDataFactory(() => ({ + nodeId: internalNode.id, + since: internalNode.start_time, + until: internalNode.end_time ?? new Date(), + }), data => { hasEvents = data.length > 0 renderEvents(data) - }, getEventFactoryOptions) + }) container.addChild(bar) container.addChild(label) diff --git a/src/models/RunGraph.ts b/src/models/RunGraph.ts index 1e3a169f..1807e4ba 100644 --- a/src/models/RunGraph.ts +++ b/src/models/RunGraph.ts @@ -48,13 +48,13 @@ export function isRunGraphNodeType(value: unknown): value is RunGraphNodeKind { export type RunGraphFetch = (runId: string) => RunGraphData | Promise -export type RunGraphFetchEventsOptions = { - since?: Date, - until?: Date, +export type RunGraphFetchEventsContext = { + nodeId: string, + since: Date, + until: Date, } export type RunGraphFetchEvents = ( - runId: string, - options?: RunGraphFetchEventsOptions, + context: RunGraphFetchEventsContext, ) => RunGraphEvent[] | Promise export type RunGraphNodeStyles = { diff --git a/src/objects/flowRunEvents.ts b/src/objects/flowRunEvents.ts index b0151808..73fec370 100644 --- a/src/objects/flowRunEvents.ts +++ b/src/objects/flowRunEvents.ts @@ -5,6 +5,7 @@ import { RunGraphEvent } from '@/models' import { waitForApplication } from '@/objects/application' import { waitForConfig } from '@/objects/config' import { EventKey, emitter, waitForEvent } from '@/objects/events' +import { waitForRunData } from '@/objects/nodes' import { layout, waitForSettings } from '@/objects/settings' let stopEventData: (() => void) | null = null @@ -14,6 +15,7 @@ export async function startFlowRunEvents(): Promise { const application = await waitForApplication() const config = await waitForConfig() const settings = await waitForSettings() + const data = await waitForRunData() const { element, render: renderEvents, update } = await runEventsFactory({ isRoot: true }) @@ -30,7 +32,11 @@ export async function startFlowRunEvents(): Promise { await renderEvents(data) } - const response = await eventDataFactory(config.runId, data => { + const response = await eventDataFactory(() => ({ + nodeId: config.runId, + since: data.start_time, + until: data.end_time ?? new Date(), + }), data => { const event: EventKey = rootGraphEvents ? 'eventDataUpdated' : 'eventDataCreated' rootGraphEvents = data