Extend idle threshold to 8 hours if execution takes longer than 5 min. (#7440)

Extend idle threshold to 8 hours if execution takes longer than 5 minutes
This commit is contained in:
Zookeeper Lee
2025-06-10 16:27:54 -04:00
committed by GitHub
parent f304577d5d
commit ff15c7b9db
2 changed files with 43 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import {
kclManager,
sceneInfra,
} from '@src/lib/singletons'
import { KclManagerEvents } from '@src/lang/KclSingleton'
import { REASONABLE_TIME_TO_REFRESH_STREAM_SIZE } from '@src/lib/timings'
import { err, reportRejection, trap } from '@src/lib/trap'
import type { IndexLoaderData } from '@src/lib/types'
@ -46,6 +47,9 @@ export const EngineStream = (props: {
const settings = useSettings()
const { state: modelingMachineState, send: modelingMachineActorSend } =
useModelingContext()
const [streamIdleMode, setStreamIdleMode] = useState(
settings.app.streamIdleMode.current
)
const { file, project } = useRouteLoaderData(PATHS.FILE) as IndexLoaderData
const last = useRef<number>(Date.now())
@ -83,7 +87,9 @@ export const EngineStream = (props: {
cameraOrbit: settings.modeling.cameraOrbit.current,
}
const streamIdleMode = settings.app.streamIdleMode.current
useEffect(() => {
setStreamIdleMode(settings.app.streamIdleMode.current)
}, [settings.app.streamIdleMode.current])
useEffect(() => {
// Will cause a useEffect loop if not checked for.
@ -143,11 +149,25 @@ export const EngineStream = (props: {
}
useEffect(() => {
// When execution takes a long time, it's most likely a user will want to
// come back and be able to say, export the model. The issue with this is
// that means the application should NOT go into idle mode for a long time!
// We've picked 8 hours to coincide with the typical length of a workday.
const onLongExecution = () => {
setStreamIdleMode(1000 * 60 * 60 * 8)
}
kclManager.addEventListener(KclManagerEvents.LongExecution, onLongExecution)
engineCommandManager.addEventListener(
EngineCommandManagerEvents.SceneReady,
play
)
return () => {
kclManager.removeEventListener(
KclManagerEvents.LongExecution,
onLongExecution
)
engineCommandManager.removeEventListener(
EngineCommandManagerEvents.SceneReady,
play

View File

@ -64,7 +64,11 @@ interface Singletons {
sceneInfra: SceneInfra
}
export class KclManager {
export enum KclManagerEvents {
LongExecution = 'long-execution',
}
export class KclManager extends EventTarget {
/**
* The artifactGraph is a client-side representation of the commands that have been sent
* see: src/lang/std/artifactGraph-README.md for a full explanation.
@ -117,6 +121,10 @@ export class KclManager {
private _fileSettings: KclSettingsAnnotation = {}
private _kclVersion: string | undefined = undefined
private singletons: Singletons
private executionTimeoutId: ReturnType<typeof setTimeout> | undefined =
undefined
// In the future this could be a setting.
public longExecutionTimeMs = 1000 * 60 * 5
engineCommandManager: EngineCommandManager
@ -261,6 +269,7 @@ export class KclManager {
engineCommandManager: EngineCommandManager,
singletons: Singletons
) {
super()
this.engineCommandManager = engineCommandManager
this.singletons = singletons
@ -570,6 +579,18 @@ export class KclManager {
return
}
clearTimeout(this.executionTimeoutId)
// We consider anything taking longer than 5 minutes a long execution.
this.executionTimeoutId = setTimeout(() => {
if (!this.isExecuting) {
clearTimeout(this.executionTimeoutId)
return
}
this.dispatchEvent(new CustomEvent(KclManagerEvents.LongExecution, {}))
}, this.longExecutionTimeMs)
return this.executeAst({ ast })
}