Skip to content

Commit

Permalink
Merge pull request #485 from PrefectHQ/enforce-occurred
Browse files Browse the repository at this point in the history
BugFix: make sure occurred is always set
  • Loading branch information
pleek91 authored Apr 1, 2024
2 parents ac1e375 + 4d2f52c commit 5f07128
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/factories/eventData.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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'

type EventDataCallback = (data: RunGraphEvent[]) => void

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export async function eventDataFactory(
runId: string,
context: MaybeRefOrGetter<RunGraphFetchEventsContext>,
callback: EventDataCallback,
options?: MaybeRefOrGetter<RunGraphFetchEventsOptions>,
) {
const runGraphData = await waitForRunData()
const config = await waitForConfig()
Expand All @@ -19,7 +18,7 @@ export async function eventDataFactory(

async function start(): Promise<void> {
try {
data = await config.fetchEvents(runId, toValue(options))
data = await config.fetchEvents(toValue(context))

callback(data)
} catch (error) {
Expand Down
16 changes: 7 additions & 9 deletions src/factories/nodeFlowRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/models/RunGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export function isRunGraphNodeType(value: unknown): value is RunGraphNodeKind {

export type RunGraphFetch = (runId: string) => RunGraphData | Promise<RunGraphData>

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<RunGraphEvent[]>

export type RunGraphNodeStyles = {
Expand Down
8 changes: 7 additions & 1 deletion src/objects/flowRunEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,6 +15,7 @@ export async function startFlowRunEvents(): Promise<void> {
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 })

Expand All @@ -30,7 +32,11 @@ export async function startFlowRunEvents(): Promise<void> {
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
Expand Down

0 comments on commit 5f07128

Please sign in to comment.