Skip to content

Commit aa68e0f

Browse files
authoredJan 6, 2023
fix: Too many requests during watching template version (#5602)
1 parent f1fe2b5 commit aa68e0f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
 

‎site/src/util/delay.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const delay = (ms: number): Promise<void> =>
2+
new Promise((res) => {
3+
setTimeout(res, ms)
4+
})

‎site/src/xServices/createTemplate/createTemplateXService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
UploadResponse,
1818
} from "api/typesGenerated"
1919
import { displayError } from "components/GlobalSnackbar/utils"
20+
import { delay } from "util/delay"
2021
import { assign, createMachine } from "xstate"
2122

2223
// for creating a new template:
@@ -345,6 +346,11 @@ export const createTemplateMachine =
345346
while (["pending", "running"].includes(status)) {
346347
version = await getTemplateVersion(version.id)
347348
status = version.job.status
349+
// Delay the verification in two seconds to not overload the server
350+
// with too many requests Maybe at some point we could have a
351+
// websocket for template version Also, preferred doing this way to
352+
// avoid a new state since we don't need to reflect it on the UI
353+
await delay(2_000)
348354
}
349355
return version
350356
},

0 commit comments

Comments
 (0)