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, kclManager,
sceneInfra, sceneInfra,
} from '@src/lib/singletons' } from '@src/lib/singletons'
import { KclManagerEvents } from '@src/lang/KclSingleton'
import { REASONABLE_TIME_TO_REFRESH_STREAM_SIZE } from '@src/lib/timings' import { REASONABLE_TIME_TO_REFRESH_STREAM_SIZE } from '@src/lib/timings'
import { err, reportRejection, trap } from '@src/lib/trap' import { err, reportRejection, trap } from '@src/lib/trap'
import type { IndexLoaderData } from '@src/lib/types' import type { IndexLoaderData } from '@src/lib/types'
@ -46,6 +47,9 @@ export const EngineStream = (props: {
const settings = useSettings() const settings = useSettings()
const { state: modelingMachineState, send: modelingMachineActorSend } = const { state: modelingMachineState, send: modelingMachineActorSend } =
useModelingContext() useModelingContext()
const [streamIdleMode, setStreamIdleMode] = useState(
settings.app.streamIdleMode.current
)
const { file, project } = useRouteLoaderData(PATHS.FILE) as IndexLoaderData const { file, project } = useRouteLoaderData(PATHS.FILE) as IndexLoaderData
const last = useRef<number>(Date.now()) const last = useRef<number>(Date.now())
@ -83,7 +87,9 @@ export const EngineStream = (props: {
cameraOrbit: settings.modeling.cameraOrbit.current, cameraOrbit: settings.modeling.cameraOrbit.current,
} }
const streamIdleMode = settings.app.streamIdleMode.current useEffect(() => {
setStreamIdleMode(settings.app.streamIdleMode.current)
}, [settings.app.streamIdleMode.current])
useEffect(() => { useEffect(() => {
// Will cause a useEffect loop if not checked for. // Will cause a useEffect loop if not checked for.
@ -143,11 +149,25 @@ export const EngineStream = (props: {
} }
useEffect(() => { 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( engineCommandManager.addEventListener(
EngineCommandManagerEvents.SceneReady, EngineCommandManagerEvents.SceneReady,
play play
) )
return () => { return () => {
kclManager.removeEventListener(
KclManagerEvents.LongExecution,
onLongExecution
)
engineCommandManager.removeEventListener( engineCommandManager.removeEventListener(
EngineCommandManagerEvents.SceneReady, EngineCommandManagerEvents.SceneReady,
play play

View File

@ -64,7 +64,11 @@ interface Singletons {
sceneInfra: SceneInfra 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 * 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. * see: src/lang/std/artifactGraph-README.md for a full explanation.
@ -117,6 +121,10 @@ export class KclManager {
private _fileSettings: KclSettingsAnnotation = {} private _fileSettings: KclSettingsAnnotation = {}
private _kclVersion: string | undefined = undefined private _kclVersion: string | undefined = undefined
private singletons: Singletons 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 engineCommandManager: EngineCommandManager
@ -261,6 +269,7 @@ export class KclManager {
engineCommandManager: EngineCommandManager, engineCommandManager: EngineCommandManager,
singletons: Singletons singletons: Singletons
) { ) {
super()
this.engineCommandManager = engineCommandManager this.engineCommandManager = engineCommandManager
this.singletons = singletons this.singletons = singletons
@ -570,6 +579,18 @@ export class KclManager {
return 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 }) return this.executeAst({ ast })
} }