export default class BackgroundJobsMain {
    /**
     * Runs constructor.
     * @param {object} args - Options.
     * @param {import("../configuration.js").default} args.configuration - Configuration.
     * @param {string} [args.host] - Hostname.
     * @param {number} [args.port] - Port.
     */
    constructor({ configuration, host, port }: {
        configuration: import("../configuration.js").default;
        host?: string | undefined;
        port?: number | undefined;
    });
    configuration: import("../configuration.js").default;
    host: string;
    port: number;
    dispatchStrategy: import("../configuration-types.js").BackgroundJobsDispatchStrategy;
    pollIntervalMs: number;
    store: BackgroundJobsStore;
    logger: Logger;
    /**
     * Narrows the runtime value to the documented type.
      @type {Set<JsonSocket>} */
    workers: Set<JsonSocket>;
    /**
     * Narrows the runtime value to the documented type.
      @type {Set<JsonSocket>} */
    readyWorkers: Set<JsonSocket>;
    /**
     * Narrows the runtime value to the documented type.
      @type {net.Server | undefined} */
    server: net.Server | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {NodeJS.Timeout | undefined} */
    _pollTimer: NodeJS.Timeout | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {NodeJS.Timeout | undefined} */
    _scheduledTimer: NodeJS.Timeout | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {NodeJS.Timeout | undefined} */
    _errorRetryTimer: NodeJS.Timeout | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {NodeJS.Timeout | undefined} */
    _orphanTimer: NodeJS.Timeout | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {BackgroundJobsScheduler | undefined} */
    scheduler: BackgroundJobsScheduler | undefined;
    _draining: boolean;
    _redrainQueued: boolean;
    _stopped: boolean;
    /**
     * Narrows the runtime value to the documented type.
      @type {(() => void) | undefined} */
    _unsubscribeBeacon: (() => void) | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {((...args: Array<?>) => void) | undefined} */
    _beaconConnectHandler: ((...args: Array<unknown>) => void) | undefined;
    /**
     * Narrows the runtime value to the documented type.
      @type {import("../beacon/client.js").default | import("../beacon/in-process-client.js").default | undefined} */
    _beaconClient: import("../beacon/client.js").default | import("../beacon/in-process-client.js").default | undefined;
    /**
     * Runs start.
     * @returns {Promise<void>} - Resolves when listening.
     */
    start(): Promise<void>;
    /**
     * Runs stop.
     * @returns {Promise<void>} - Resolves when closed.
     */
    stop(): Promise<void>;
    /**
     * Runs close workers.
      @returns {void} */
    _closeWorkers(): void;
    /**
     * Runs clear timers.
      @returns {void} */
    _clearTimers(): void;
    /**
     * Runs disconnect beacon handlers.
      @returns {void} */
    _disconnectBeaconHandlers(): void;
    /**
     * Runs stop beacon and server.
      @returns {Promise<void>} */
    _stopBeaconAndServer(): Promise<void>;
    /**
     * Runs close server and database connections.
      @returns {Promise<void>} */
    _closeServerAndDatabaseConnections(): Promise<void>;
    /**
     * Runs close server.
      @returns {Promise<void>} */
    _closeServer(): Promise<void>;
    /**
     * Runs get port.
     * @returns {number} - Bound port.
     */
    getPort(): number;
    /**
     * Wires up the dispatch-triggering signal sources for the configured
     * strategy. In `"beacon"` mode (default) this means subscribing to the
     * `velocious-background-jobs-dispatch` channel for cross-process
     * wake-ups, listening for Beacon (re)connects to catch up on missed
     * work, and relying on direct in-process calls from `_handleEnqueue`,
     * `_handleJobComplete`/`Failed`, worker hello/ready, and the
     * scheduled-job `setTimeout`. In `"polling"` mode we restore the
     * legacy fixed-interval poll for users who want the previous behavior.
     * @returns {void}
     */
    _setupDispatchTriggers(): void;
    /**
     * Publishes a dispatch wake-up on the Beacon channel. No-op in polling
     * mode or when Beacon is not connected; in those cases the direct
     * in-process `_drain()` call in the enqueue/handle paths is sufficient
     * (there are no other processes to notify).
     * @returns {void}
     */
    _notifyEnqueued(): void;
    /**
     * Runs handle connection.
     * @param {import("net").Socket} socket - Socket.
     * @returns {void}
     */
    _handleConnection(socket: import("net").Socket): void;
    /**
     * Runs handle socket message.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobSocketMessage} args.message - Socket message.
     * @param {import("./types.js").BackgroundJobSocketRole | null} args.role - Current socket role.
     * @returns {import("./types.js").BackgroundJobSocketRole | null} - Updated socket role.
     */
    _handleSocketMessage({ jsonSocket, message, role }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobSocketMessage;
        role: import("./types.js").BackgroundJobSocketRole | null;
    }): import("./types.js").BackgroundJobSocketRole | null;
    /**
     * Runs handle roleless socket message.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobSocketMessage} args.message - Socket message.
     * @returns {import("./types.js").BackgroundJobSocketRole | null} - New socket role.
     */
    _handleRolelessSocketMessage({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobSocketMessage;
    }): import("./types.js").BackgroundJobSocketRole | null;
    /**
     * Runs handle client socket message.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobSocketMessage} args.message - Socket message.
     * @returns {void}
     */
    _handleClientSocketMessage({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobSocketMessage;
    }): void;
    /**
     * Runs handle worker socket message.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobSocketMessage} args.message - Socket message.
     * @returns {void}
     */
    _handleWorkerSocketMessage({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobSocketMessage;
    }): void;
    /**
     * Runs handle reporter socket message.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobSocketMessage} args.message - Socket message.
     * @returns {void}
     */
    _handleReporterSocketMessage({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobSocketMessage;
    }): void;
    /**
     * Runs handle worker ready.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobReadyMessage} args.message - Ready message.
     * @returns {void}
     */
    _handleWorkerReady({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobReadyMessage;
    }): void;
    /**
     * Runs handle worker draining.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @returns {void}
     */
    _handleWorkerDraining({ jsonSocket }: {
        jsonSocket: JsonSocket;
    }): void;
    /**
     * Runs handle enqueue.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobEnqueueMessage} args.message - Message.
     * @returns {Promise<void>} - Resolves when handled.
     */
    _handleEnqueue({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobEnqueueMessage;
    }): Promise<void>;
    /**
     * Runs handle job complete.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobCompleteMessage} args.message - Message.
     * @returns {Promise<void>} - Resolves when handled.
     */
    _handleJobComplete({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobCompleteMessage;
    }): Promise<void>;
    /**
     * Runs handle job failed.
     * @param {object} args - Options.
     * @param {JsonSocket} args.jsonSocket - JSON socket.
     * @param {import("./types.js").BackgroundJobFailedMessage} args.message - Message.
     * @returns {Promise<void>} - Resolves when handled.
     */
    _handleJobFailed({ jsonSocket, message }: {
        jsonSocket: JsonSocket;
        message: import("./types.js").BackgroundJobFailedMessage;
    }): Promise<void>;
    /**
     * Runs emit background job failed.
     * @param {{error: ?, handedOffAtMs?: number, job: import("./types.js").BackgroundJobRow, workerId?: string}} args - Failure event data.
     * @returns {void}
     */
    _emitBackgroundJobFailed({ error, handedOffAtMs, job, workerId }: {
        error: unknown;
        handedOffAtMs?: number;
        job: import("./types.js").BackgroundJobRow;
        workerId?: string;
    }): void;
    /**
     * Runs normalize failure error.
     * @param {?} error - Reported failure value.
     * @returns {Error} Normalized error.
     */
    _normalizeFailureError(error: unknown): Error;
    /**
     * Runs error from unknown failure.
     * @param {?} error - Reported failure value.
     * @returns {Error} Normalized error.
     */
    _errorFromUnknownFailure(error: unknown): Error;
    /**
     * Runs message from unknown failure.
     * @param {?} error - Reported failure value.
     * @returns {string} Error message.
     */
    _messageFromUnknownFailure(error: unknown): string;
    /**
     * Runs has string failure.
     * @param {?} error - Reported failure value.
     * @returns {error is string} Whether the value is a non-empty string.
     */
    _hasStringFailure(error: unknown): error is string;
    /**
     * Runs copy string failure stack.
     * @param {object} args - Options.
     * @param {?} args.error - Reported failure value.
     * @param {Error} args.normalizedError - Normalized error.
     * @returns {void}
     */
    _copyStringFailureStack({ error, normalizedError }: {
        error: unknown;
        normalizedError: Error;
    }): void;
    /**
     * Drains all dispatchable jobs to ready workers, then arms the
     * scheduled-job timer for the next future `scheduled_at_ms`. Coalesces
     * concurrent triggers: a wake-up that lands while a drain is in
     * flight just sets a re-drain flag and lets the in-flight drain
     * re-loop after it finishes, so no signal is dropped but no two
     * drains run in parallel.
     *
     * Resilience: in beacon mode this is the sole wake-up path for
     * already-queued work, so a transient DB error during the drain (e.g.
     * `nextAvailableJob()` rejecting) must not strand the queue until the
     * next external signal. On any error we log it and arm a one-shot
     * retry via `_scheduleErrorRetry` using `pollIntervalMs` as the
     * cadence; on success the retry timer is cleared. Polling-mode runs
     * `_drain` from its own interval, so the retry timer is a no-op there.
     * @returns {Promise<void>}
     */
    _drain(): Promise<void>;
    /**
     * Runs start drain.
     * @returns {boolean} - Whether the drain should continue.
     */
    _startDrain(): boolean;
    /**
     * Runs finish drain.
     * @param {object} args - Options.
     * @param {boolean} args.errored - Whether the drain hit an error.
     * @returns {Promise<void>} - Resolves after follow-up timers are handled.
     */
    _finishDrain({ errored }: {
        errored: boolean;
    }): Promise<void>;
    /**
     * Runs arm scheduled timer or retry.
     * @returns {Promise<void>} - Resolves after scheduled timer handling.
     */
    _armScheduledTimerOrRetry(): Promise<void>;
    /**
     * Runs clear error retry timer.
      @returns {void} */
    _clearErrorRetryTimer(): void;
    /**
     * Runs queue drain if already running.
     * @returns {boolean} - Whether another drain is already in progress.
     */
    _queueDrainIfAlreadyRunning(): boolean;
    /**
     * Runs drain until idle.
     * @returns {Promise<boolean>} - Whether the drain hit an error.
     */
    _drainUntilIdle(): Promise<boolean>;
    /**
     * Runs run drain loop.
     * @returns {Promise<boolean>} - Whether the drain hit an error.
     */
    _runDrainLoop(): Promise<boolean>;
    /**
     * Runs drain once with error report.
     * @returns {Promise<boolean>} - Whether one drain pass failed.
     */
    _drainOnceWithErrorReport(): Promise<boolean>;
    /**
     * Arms a one-shot `setTimeout` to retry `_drain` after a transient
     * failure. Idempotent — repeated calls while a retry is already
     * pending are no-ops. Polling mode already retries via its own
     * interval, so this is a no-op in that mode.
     * @returns {void}
     */
    _scheduleErrorRetry(): void;
    /**
     * Inner drain loop: pulls eligible queued jobs and hands them off to
     * ready workers until one of them runs out.
     * @returns {Promise<void>}
     */
    _drainOnce(): Promise<void>;
    /**
     * Runs next available job for ready workers.
     * @returns {Promise<import("./types.js").BackgroundJobRow | null>} - Next queued job matching ready worker capacity.
     */
    nextAvailableJobForReadyWorkers(): Promise<import("./types.js").BackgroundJobRow | null>;
    /**
     * Runs ready worker execution modes.
     * @returns {import("./types.js").BackgroundJobExecutionMode[]} - Execution modes currently accepted by ready workers.
     */
    readyWorkerExecutionModes(): import("./types.js").BackgroundJobExecutionMode[];
    /**
     * Runs add accepted execution modes.
     * @param {object} args - Options.
     * @param {Set<import("./types.js").BackgroundJobExecutionMode>} args.executionModes - Accepted modes.
     * @param {JsonSocket} args.worker - Worker socket.
     * @returns {void}
     */
    _addAcceptedExecutionModes({ executionModes, worker }: {
        executionModes: Set<import("./types.js").BackgroundJobExecutionMode>;
        worker: JsonSocket;
    }): void;
    /**
     * Runs ready worker for job.
     * @param {import("./types.js").BackgroundJobRow} job - Job being handed off.
     * @returns {JsonSocket | undefined} - Ready worker for the job type.
     */
    readyWorkerForJob(job: import("./types.js").BackgroundJobRow): JsonSocket | undefined;
    /**
     * Runs worker accepts job.
     * @param {object} args - Options.
     * @param {import("./types.js").BackgroundJobRow} args.job - Job being handed off.
     * @param {JsonSocket} args.worker - Worker socket.
     * @returns {boolean} - Whether the worker accepts the job mode.
     */
    _workerAcceptsJob({ job, worker }: {
        job: import("./types.js").BackgroundJobRow;
        worker: JsonSocket;
    }): boolean;
    /**
     * Arms a single `setTimeout` for the soonest future-scheduled job's
     * `scheduled_at_ms`. Replaces the second responsibility of the legacy
     * 1-second poll (becoming-eligible scheduled jobs). The timer is
     * idempotently re-armed at the end of every drain.
     * @returns {Promise<void>}
     */
    _armScheduledTimer(): Promise<void>;
    _sweepOrphans(): Promise<void>;
}
/**
 * WorkerExecutionModeCapability type.
 */
export type WorkerExecutionModeCapability = {
    /**
     * - Execution mode.
     */
    executionMode: import("./types.js").BackgroundJobExecutionMode;
    /**
     * - Whether the worker accepts this mode.
     */
    accepts: (worker: JsonSocket) => boolean;
};
import BackgroundJobsStore from "./store.js";
import Logger from "../logger.js";
import JsonSocket from "./json-socket.js";
import net from "net";
import BackgroundJobsScheduler from "./scheduler.js";
//# sourceMappingURL=main.d.ts.map