export default class BackgroundJobsWorker {
    /**
     * Runs constructor.
     * @param {object} [args] - Options.
     * @param {import("../configuration.js").default} [args.configuration] - Configuration.
     * @param {string} [args.host] - Hostname.
     * @param {number} [args.port] - Port.
     * @param {number} [args.maxConcurrentForkedJobs] - Override the process runner concurrency cap from `configuration.getBackgroundJobsConfig()`.
     * @param {number} [args.maxConcurrentInlineJobs] - Override the inline-job concurrency cap from `configuration.getBackgroundJobsConfig()`.
     * @param {number} [args.forkedChildSigkillGraceMs] - Override the grace period between SIGTERM and SIGKILL when reaping lingering process runners on stop.
     */
    constructor({ configuration, host, port, maxConcurrentForkedJobs, maxConcurrentInlineJobs, forkedChildSigkillGraceMs }?: {
        configuration?: import("../configuration.js").default | undefined;
        host?: string | undefined;
        port?: number | undefined;
        maxConcurrentForkedJobs?: number | undefined;
        maxConcurrentInlineJobs?: number | undefined;
        forkedChildSigkillGraceMs?: number | undefined;
    });
    /**
     * Narrows the runtime value to the documented type.
      @type {Promise<import("../configuration.js").default>} */
    configurationPromise: Promise<import("../configuration.js").default>;
    /**
     * Narrows the runtime value to the documented type.
      @type {import("../configuration.js").default | undefined} */
    configuration: import("../configuration.js").default | undefined;
    host: string | undefined;
    port: number | undefined;
    /**
     * Constructor override for the inline-job concurrency cap. When unset
     * the cap is read from `configuration.getBackgroundJobsConfig()` in
     * `start()` (default: 4).
     * @type {number | undefined}
     */
    maxConcurrentInlineJobsOverride: number | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {number | undefined} */
    maxConcurrentForkedJobsOverride: number | undefined;
    /**
     * Resolved cap for inline-job concurrency. Set in `start()`; defaults to
     * 4 if no configuration value is available.
     * @type {number}
     */
    maxConcurrentInlineJobs: number;
    /**
     * Narrows the runtime value to the documented type.
      @type {number} */
    maxConcurrentForkedJobs: number;
    /**
     * Grace period between SIGTERM and SIGKILL when reaping process runners that
     * outlast a bounded shutdown drain.
     * @type {number}
     */
    forkedChildSigkillGraceMs: number;
    shouldStop: boolean;
    workerId: `${string}-${string}-${string}-${string}-${string}`;
    /**
     * Narrows the runtime value to the documented type.
      @type {JsonSocket | undefined} */
    jsonSocket: JsonSocket | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {BackgroundJobsStatusReporter | undefined} */
    statusReporter: BackgroundJobsStatusReporter | undefined;
    /**
     * Up to `this.maxConcurrentInlineJobs` of these run in parallel. They
     * share the worker's process and DB connection pool, so concurrency is
     * about overlapping I/O waits — use forking for memory isolation across
     * long-running jobs and for using more cores.
     * @type {Set<Promise<void>>}
     */
    inflightInlineJobs: Set<Promise<void>>;
    /**
     * In-flight process runner exit promises. Tracked so process-job handoff
     * stays bounded while running and so a graceful `stop()` can drain them.
     * @type {Set<Promise<void>>}
     */
    inflightProcessJobs: Set<Promise<void>>;
    /**
     * Live process runner child processes, kept so a graceful `stop()` can
     * terminate any that outlast the shutdown drain instead of orphaning them
     * across a deploy (where they would keep running against deleted release
     * code and holding database connections).
     * @type {Set<import("node:child_process").ChildProcess>}
     */
    inflightProcessChildren: Set<import("node:child_process").ChildProcess>;
    /**
     * Runs start.
     * @returns {Promise<void>} - Resolves when connected.
     */
    start(): Promise<void>;
    /**
     * Gracefully stops the worker: announces draining to the main process so
     * no new jobs are dispatched, waits for in-flight inline jobs and process
     * runners to finish (so their results can be reported), then closes the
     * socket and disconnects from the beacon.
     *
     * Process runners are child processes. When a `timeoutMs` is given (e.g. a
     * deploy draining the old release) any runner still alive after the drain
     * window is terminated (SIGTERM, then SIGKILL) rather than left to orphan
     * across the deploy. With no `timeoutMs` the drain waits for runners to
     * finish on their own.
     * @param {object} [args] - Options.
     * @param {number} [args.timeoutMs] - Max wait for in-flight jobs (per phase) in ms.
     * @returns {Promise<void>} - Resolves when stopped.
     */
    stop({ timeoutMs }?: {
        timeoutMs?: number | undefined;
    }): Promise<void>;
    /**
     * Waits for a set of in-flight job promises to settle, optionally bounded by
     * `timeoutMs`.
     * @param {Set<Promise<void>>} inflight - In-flight job promises.
     * @param {number} [timeoutMs] - Max wait in ms; unbounded when omitted.
     * @returns {Promise<void>} - Resolves when settled or the timeout elapses.
     */
    _drainInflight(inflight: Set<Promise<void>>, timeoutMs?: number): Promise<void>;
    /**
     * Terminates any process runner children still alive after the drain window so
     * they don't outlive the worker as orphans. SIGTERM lets the runner close its
     * connections cleanly; survivors are SIGKILLed after a short grace.
     * @returns {Promise<void>} - Resolves once survivors have been signalled.
     */
    _terminateProcessChildren(): Promise<void>;
    _connect(): Promise<void>;
    /**
     * Runs handle job.
     * @param {import("./types.js").BackgroundJobPayload} payload - Payload.
     * @returns {Promise<void>} - Resolves when done.
     */
    _handleJob(payload: import("./types.js").BackgroundJobPayload): Promise<void>;
    /**
     * Runs start process job.
     * @param {object} args - Options.
     * @param {import("./types.js").BackgroundJobExecutionMode} args.executionMode - Execution mode.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Payload.
     * @returns {Promise<void>} - Resolves when the process job exits.
     */
    _startProcessJob({ executionMode, payload }: {
        executionMode: import("./types.js").BackgroundJobExecutionMode;
        payload: import("./types.js").BackgroundJobPayload & {
            id: string;
        };
    }): Promise<void>;
    /**
     * Runs handle inline job.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} payload - Payload.
     * @returns {void}
     */
    _handleInlineJob(payload: import("./types.js").BackgroundJobPayload & {
        id: string;
    }): void;
    /**
     * Runs execution mode for payload.
     * @param {import("./types.js").BackgroundJobPayload} payload - Payload.
     * @returns {import("./types.js").BackgroundJobExecutionMode} - Execution mode.
     */
    _executionModeForPayload(payload: import("./types.js").BackgroundJobPayload): import("./types.js").BackgroundJobExecutionMode;
    /**
     * Runs normalize execution mode.
     * @param {string} executionMode - Execution mode.
     * @returns {import("./types.js").BackgroundJobExecutionMode} - Normalized execution mode.
     */
    _normalizeExecutionMode(executionMode: string): import("./types.js").BackgroundJobExecutionMode;
    /**
     * Runs track process job.
     * @param {Promise<void>} processJob - Process job promise.
     * @returns {void}
     */
    _trackProcessJob(processJob: Promise<void>): void;
    /**
     * Runs run inline job and report.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} payload - Payload with required id.
     * @returns {Promise<void>} - Resolves when complete (success or failure reported).
     */
    _runInlineJobAndReport(payload: import("./types.js").BackgroundJobPayload & {
        id: string;
    }): Promise<void>;
    /**
     * Tells main we're ready for the next job — but only if we haven't been
     * asked to drain. Once we've sent `draining` we don't want to take more
     * work.
     * @returns {void}
     */
    _sendReadyIfRunning(): void;
    /**
     * Runs ready message.
     * @returns {import("./types.js").BackgroundJobSocketMessage | null} - Ready message or null when the worker has no capacity.
     */
    _readyMessage(): import("./types.js").BackgroundJobSocketMessage | null;
    /**
     * Runs run job inline.
     * @param {import("./types.js").BackgroundJobPayload} payload - Payload.
     * @returns {Promise<void>} - Resolves when done.
     */
    _runJobInline(payload: import("./types.js").BackgroundJobPayload): Promise<void>;
    /**
     * Runs fork job.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} payload - Payload.
     * @returns {Promise<void>} - Resolves when the forked runner exits or fork fails.
     */
    _forkJob(payload: import("./types.js").BackgroundJobPayload & {
        id: string;
    }): Promise<void>;
    /**
     * Runs create forked child.
     * @returns {import("node:child_process").ChildProcess} - Forked child process.
     */
    _createForkedChild(): import("node:child_process").ChildProcess;
    /**
     * Runs wait for forked child.
     * @param {object} args - Options.
     * @param {import("node:child_process").ChildProcess} args.child - Forked child process.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Payload.
     * @returns {Promise<void>} - Resolves when the child exits.
     */
    _waitForForkedChild({ child, payload }: {
        child: import("node:child_process").ChildProcess;
        payload: import("./types.js").BackgroundJobPayload & {
            id: string;
        };
    }): Promise<void>;
    /**
     * Runs handle forked child exit.
     * @param {object} args - Options.
     * @param {import("node:child_process").ChildProcess} args.child - Forked child process.
     * @param {number | null} args.code - Exit code.
     * @param {NodeJS.Signals | null} args.signal - Exit signal.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Payload.
     * @param {(value: void) => void} args.resolve - Promise resolver.
     * @returns {Promise<void>} - Resolves after failure is reported.
     */
    _handleForkedChildExit({ child, code, signal, payload, resolve }: {
        child: import("node:child_process").ChildProcess;
        code: number | null;
        signal: NodeJS.Signals | null;
        payload: import("./types.js").BackgroundJobPayload & {
            id: string;
        };
        resolve: (value: void) => void;
    }): Promise<void>;
    /**
     * Runs forked child exited cleanly.
     * @param {object} args - Options.
     * @param {number | null} args.code - Exit code.
     * @param {NodeJS.Signals | null} args.signal - Exit signal.
     * @returns {boolean} - Whether the child exited cleanly.
     */
    _forkedChildExitedCleanly({ code, signal }: {
        code: number | null;
        signal: NodeJS.Signals | null;
    }): boolean;
    /**
     * Runs handle forked child error.
     * @param {object} args - Options.
     * @param {import("node:child_process").ChildProcess} args.child - Forked child process.
     * @param {Error} args.error - Child process error.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Payload.
     * @param {(value: void) => void} args.resolve - Promise resolver.
     * @returns {Promise<void>} - Resolves after failure is reported.
     */
    _handleForkedChildError({ child, error, payload, resolve }: {
        child: import("node:child_process").ChildProcess;
        error: Error;
        payload: import("./types.js").BackgroundJobPayload & {
            id: string;
        };
        resolve: (value: void) => void;
    }): Promise<void>;
    /**
     * Runs send forked payload.
     * @param {object} args - Options.
     * @param {import("node:child_process").ChildProcess} args.child - Forked child process.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Payload.
     * @returns {void}
     */
    _sendForkedPayload({ child, payload }: {
        child: import("node:child_process").ChildProcess;
        payload: import("./types.js").BackgroundJobPayload & {
            id: string;
        };
    }): void;
    /**
     * Runs report forked child failure.
     * @param {object} args - Options.
     * @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Payload.
     * @param {?} args.error - Error.
     * @returns {Promise<void>} - Resolves after failure is reported.
     */
    _reportForkedChildFailure({ payload, error }: {
        payload: import("./types.js").BackgroundJobPayload & {
            id: string;
        };
        error: unknown;
    }): Promise<void>;
    /**
     * Runs spawn job.
     * @param {import("./types.js").BackgroundJobPayload} payload - Payload.
     * @returns {Promise<void>} - Resolves when the spawned runner exits or spawn fails.
     */
    _spawnJob(payload: import("./types.js").BackgroundJobPayload): Promise<void>;
    /**
     * Runs report job result.
     * @param {object} args - Options.
     * @param {string} args.jobId - Job id.
     * @param {"completed" | "failed"} args.status - Status.
     * @param {?} [args.error] - Error.
     * @param {number} [args.handedOffAtMs] - Handed off timestamp.
     * @param {string} [args.workerId] - Worker id.
     * @returns {Promise<void>} - Resolves when reported.
     */
    _reportJobResult({ jobId, status, error, handedOffAtMs, workerId }: {
        jobId: string;
        status: "completed" | "failed";
        error?: unknown;
        handedOffAtMs?: number | undefined;
        workerId?: string | undefined;
    }): Promise<void>;
}
import JsonSocket from "./json-socket.js";
import BackgroundJobsStatusReporter from "./status-reporter.js";
//# sourceMappingURL=worker.d.ts.map