Skip to content

Commit

Permalink
Merge pull request #325 from PrefectHQ/data-fetch-interval
Browse files Browse the repository at this point in the history
Make the data refresh interval based on the number of nodes
  • Loading branch information
pleek91 authored Nov 8, 2023
2 parents e015786 + c1f8f32 commit 8c593ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo/data/graph-small.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"start_time": "2023-09-27T15:50:39.425118+00:00",
"end_time": "2023-09-27T15:51:11.922153+00:00",
"end_time": null,
"root_node_ids": [
"ea9d7c12-7418-4ea9-b33d-189f22f737af",
"7d93e182-e17f-40a2-a0c3-784d1d0e7ff5",
Expand Down
1 change: 0 additions & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export const DEFAULT_POLL_INTERVAL = 1000
export const DEFAULT_NODES_CONTAINER_NAME = 'nodes-container'
export const DEFAULT_NODE_CONTAINER_NAME = 'node-container'
export const DEFAULT_EDGE_CONTAINER_NAME = 'edge-container'
Expand Down
10 changes: 8 additions & 2 deletions src/factories/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_POLL_INTERVAL } from '@/consts'
import { millisecondsInSecond } from 'date-fns'
import { RunGraphData } from '@/models/RunGraph'
import { waitForConfig } from '@/objects/config'

Expand All @@ -22,7 +22,7 @@ export async function dataFactory(runId: string, callback: DataCallback) {


if (data && !data.end_time) {
interval = setTimeout(() => start(), DEFAULT_POLL_INTERVAL)
interval = setTimeout(() => start(), getIntervalForDataSize(data))
}
}

Expand All @@ -36,4 +36,10 @@ export async function dataFactory(runId: string, callback: DataCallback) {
stop,
}

}

function getIntervalForDataSize(data: RunGraphData): number {
const intervalBasedOnNodeCount = Math.floor(data.nodes.size / millisecondsInSecond) * millisecondsInSecond

return Math.max(millisecondsInSecond, intervalBasedOnNodeCount)
}

0 comments on commit 8c593ce

Please sign in to comment.