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