mirror of
https://github.com/coder/coder.git
synced 2025-07-21 01:28:49 +00:00
fix: Too many requests during watching template version (#5602)
This commit is contained in:
4
site/src/util/delay.ts
Normal file
4
site/src/util/delay.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export const delay = (ms: number): Promise<void> =>
|
||||
new Promise((res) => {
|
||||
setTimeout(res, ms)
|
||||
})
|
@ -17,6 +17,7 @@ import {
|
||||
UploadResponse,
|
||||
} from "api/typesGenerated"
|
||||
import { displayError } from "components/GlobalSnackbar/utils"
|
||||
import { delay } from "util/delay"
|
||||
import { assign, createMachine } from "xstate"
|
||||
|
||||
// for creating a new template:
|
||||
@ -345,6 +346,11 @@ export const createTemplateMachine =
|
||||
while (["pending", "running"].includes(status)) {
|
||||
version = await getTemplateVersion(version.id)
|
||||
status = version.job.status
|
||||
// Delay the verification in two seconds to not overload the server
|
||||
// with too many requests Maybe at some point we could have a
|
||||
// websocket for template version Also, preferred doing this way to
|
||||
// avoid a new state since we don't need to reflect it on the UI
|
||||
await delay(2_000)
|
||||
}
|
||||
return version
|
||||
},
|
||||
|
Reference in New Issue
Block a user