* Save current state to file system
()
| 113 | * Save current state to file system |
| 114 | */ |
| 115 | async 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 |
no outgoing calls
no test coverage detected