(input?: {
readonly onlyKind?: ExecutorLocalServerKind;
})
| 370 | }); |
| 371 | |
| 372 | const takeOverActiveLocalServer = (input?: { |
| 373 | readonly onlyKind?: ExecutorLocalServerKind; |
| 374 | }): Effect.Effect< |
| 375 | ExecutorLocalServerManifest | null, |
| 376 | Error, |
| 377 | FileSystem.FileSystem | PlatformPath.Path |
| 378 | > => |
| 379 | Effect.gen(function* () { |
| 380 | const manifest = yield* readLocalServerManifest(); |
| 381 | if (!manifest) return null; |
| 382 | if (input?.onlyKind && manifest.kind !== input.onlyKind) return null; |
| 383 | |
| 384 | if (!isPidAlive(manifest.pid) || manifest.pid === process.pid) { |
| 385 | yield* removeLocalServerManifestIfOwnedBy({ pid: manifest.pid }).pipe(Effect.ignore); |
| 386 | return null; |
| 387 | } |
| 388 | |
| 389 | yield* terminatePid(manifest.pid).pipe(Effect.ignore); |
| 390 | const stopped = yield* waitForUnreachable({ |
| 391 | check: isServerReachable(manifest.connection.origin), |
| 392 | timeoutMs: DAEMON_STOP_TIMEOUT_MS, |
| 393 | intervalMs: DAEMON_BOOT_POLL_MS, |
| 394 | }); |
| 395 | if (!stopped) { |
| 396 | return yield* Effect.fail( |
| 397 | new Error( |
| 398 | [ |
| 399 | `The existing Executor ${manifest.kind} at ${manifest.connection.origin} (pid ${manifest.pid}) did not stop within ${DAEMON_STOP_TIMEOUT_MS / 1000}s.`, |
| 400 | "Stop it manually and re-run.", |
| 401 | ].join("\n"), |
| 402 | ), |
| 403 | ); |
| 404 | } |
| 405 | |
| 406 | yield* removeLocalServerManifestIfOwnedBy({ pid: manifest.pid }).pipe(Effect.ignore); |
| 407 | return manifest; |
| 408 | }); |
| 409 | |
| 410 | const publishLocalServerManifest = (input: { |
| 411 | readonly kind: ExecutorLocalServerKind; |
no test coverage detected