MCPcopy Create free account
hub / github.com/CodeFox-Repo/codefox / saveState

Function saveState

frontend/src/app/api/runProject/route.ts:115–142  ·  view source on GitHub ↗

* Save current state to file system

()

Source from the content-addressed store, hash-verified

113 * Save current state to file system
114 */
115async function saveState() {
116 if (isUpdatingState) {
117 // If an update is already in progress, wait
118 await new Promise((resolve) => setTimeout(resolve, 100));
119 return saveState();
120 }
121
122 isUpdatingState = true;
123 try {
124 // Save container state
125 const containerObject = Object.fromEntries(runningContainers);
126 await fs.promises.writeFile(
127 CONTAINER_STATE_FILE,
128 JSON.stringify(containerObject, null, 2)
129 );
130
131 // Save port state
132 const portsArray = Array.from(allocatedPorts);
133 await fs.promises.writeFile(
134 PORT_STATE_FILE,
135 JSON.stringify(portsArray, null, 2)
136 );
137 } catch (error) {
138 logger.error('Error saving state:', error);
139 } finally {
140 isUpdatingState = false;
141 }
142}
143
144/**
145 * Find an available port

Callers 5

initializeStateFunction · 0.85
scanPortsFunction · 0.85
runDockerContainerFunction · 0.85
route.tsFile · 0.85
GETFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected