(input?: {
readonly onlyKind?: ExecutorLocalServerKind;
})
| 387 | }); |
| 388 | |
| 389 | const takeOverActiveLocalServer = (input?: { |
| 390 | readonly onlyKind?: ExecutorLocalServerKind; |
| 391 | }): Effect.Effect< |
| 392 | ExecutorLocalServerManifest | null, |
| 393 | Error, |
| 394 | FileSystem.FileSystem | PlatformPath.Path |
| 395 | > => |
| 396 | Effect.gen(function* () { |
| 397 | const manifest = yield* readLocalServerManifest(); |
| 398 | if (!manifest) return null; |
| 399 | if (input?.onlyKind && manifest.kind !== input.onlyKind) return null; |
| 400 | |
| 401 | if (!isPidAlive(manifest.pid) || manifest.pid === process.pid) { |
| 402 | yield* removeLocalServerManifestIfOwnedBy({ pid: manifest.pid }).pipe(Effect.ignore); |
| 403 | return null; |
| 404 | } |
| 405 | |
| 406 | yield* terminatePid(manifest.pid).pipe(Effect.ignore); |
| 407 | const stopped = yield* waitForUnreachable({ |
| 408 | check: isServerReachable(manifest.connection.origin), |
| 409 | timeoutMs: DAEMON_STOP_TIMEOUT_MS, |
| 410 | intervalMs: DAEMON_BOOT_POLL_MS, |
| 411 | }); |
| 412 | if (!stopped) { |
| 413 | return yield* Effect.fail( |
| 414 | new Error( |
| 415 | [ |
| 416 | `The existing Executor ${manifest.kind} at ${manifest.connection.origin} (pid ${manifest.pid}) did not stop within ${DAEMON_STOP_TIMEOUT_MS / 1000}s.`, |
| 417 | "Stop it manually and re-run.", |
| 418 | ].join("\n"), |
| 419 | ), |
| 420 | ); |
| 421 | } |
| 422 | |
| 423 | yield* removeLocalServerManifestIfOwnedBy({ pid: manifest.pid }).pipe(Effect.ignore); |
| 424 | return manifest; |
| 425 | }); |
| 426 | |
| 427 | const publishLocalServerManifest = (input: { |
| 428 | readonly kind: ExecutorLocalServerKind; |
no test coverage detected