import { Backend, CancelExecutionResult, EnqueueResult, ExecutionFilters, GetExecutionResult, ListExecutionAttemptsResult, ListExecutionsResult, PageRequest, ReRunExecutionResult, RescheduleExecutionResult } from "./backend"; import { Duration } from "./utils"; export declare let backend: Backend; /** * Check if defer is enqueuing on the Defer cloud * @returns {boolean} */ export declare const deferEnabled: () => boolean; export interface ExecutionMetadata { [key: string]: string; } export type NextRouteString = `/api/${string}`; export interface Manifest { name: string; version: number; cron?: string; retry?: RetryPolicy; concurrency?: number | undefined; maxDuration?: number | undefined; maxConcurrencyAction: "keep" | "cancel" | undefined; } export interface RetryPolicy { maxAttempts: number; initialInterval: number; randomizationFactor: number; multiplier: number; maxInterval: number; } export type DeferableFunction = (...args: any[]) => Promise; export interface ExecutionOptions { delay?: Duration | Date; metadata?: ExecutionMetadata; discardAfter?: Duration | Date; } export interface DeferredFunction { (...args: Parameters): Promise; __metadata: Manifest; __fn: F; __execOptions?: ExecutionOptions; } export interface DeferredFunctionConfiguration { retry?: boolean | number | Partial; concurrency?: number; maxDuration?: number; maxConcurrencyAction?: "keep" | "cancel"; } /** * Define a deferred function * @template F * @param {F} fn * @param {DeferredFunctionConfiguration=} config * @returns {DeferredFunction} */ export declare function defer(fn: F, config?: DeferredFunctionConfiguration): DeferredFunction; export declare namespace defer { var cron: (fn: F, cronExpr: string, config?: DeferredFunctionConfiguration | undefined) => DeferredFunction; } /** * Delay an execution * @template F * @param {DeferredFunction} fn * @param {Duration | Date} delay * @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options) * @returns {DeferredFunction} */ export declare function delay(fn: DeferredFunction, delay: Duration | Date): DeferredFunction; /** * Add metadata to an execution * @template F * @param {DeferredFunction} fn * @param {ExecutionMetadata} metadata * @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options) * @returns {DeferredFunction} */ export declare function addMetadata(fn: DeferredFunction, metadata: ExecutionMetadata): DeferredFunction; /** * Discard an execution if not started after a given interval * @template F * @param {DeferredFunction} fn * @param {Duration | Date} value * @deprecated Prefer `assignOptions()` (https://www.defer.run/docs/references/defer-client/assign-options) * @returns {DeferredFunction} */ export declare function discardAfter(fn: DeferredFunction, value: Duration | Date): DeferredFunction; /** * Assign execution options to a deferred function * @template F * @param {DeferredFunction} fn * @param {ExecutionOptions} options * @returns {DeferredFunction} */ export declare function assignOptions(fn: DeferredFunction, options: ExecutionOptions): DeferredFunction; /** * Get an execution * @async * @param {string} id * @throws {ExecutionNotFound} when execution does not exists * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function getExecution(id: string): Promise; /** * Get an execution result * @async * @template T * @param {string} id * @throws {ExecutionNotFound} when execution does not exists * @throws {ExecutionResultNotAvailableYet} when result is not yet available * @throws {ExecutionResultNotAvailable} when there's no result * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function getExecutionResult(id: string): Promise; /** * Cancel an execution * @async * @param {string} id * @param {boolean} force * @throws {ExecutionNotFound} when execution does not exists * @throws {ExecutionAbortingAlreadyInProgress} when execution is started * @throws {ExecutionNotCancellable} when execution cannot be cancelled * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function cancelExecution(id: string, force?: boolean): Promise; /** * Reschedule an execution * @async * @param {string} id * @param {Duration | Date | undefined} value * @throws {ExecutionNotFound} when execution does not exists * @throws {ExecutionNotReschedulable} when execution has started and/or completed. * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function rescheduleExecution(id: string, value?: Duration | Date | undefined): Promise; /** * ReRun an execution * @async * @param {string} id * @throws {ExecutionNotFound} when execution does not exists * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function reRunExecution(id: string): Promise; /** * List an execution attempts * @deprecated Prefer `listExecutionAttempts()` (https://www.defer.run/docs/references/defer-client/list-execution-attempts) * @async * @param {string} id * @throws {ExecutionNotFound} when execution does not exists * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function getExecutionTries(id: string): Promise; /** * List an execution attempts * @async * @param {string} id * @param {PageRequest=} page * @param {ExecutionFilters=} filters * @throws {ExecutionNotFound} when execution does not exists * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function listExecutionAttempts(id: string, page?: PageRequest, filters?: ExecutionFilters): Promise; /** * List executions * @async * @param {PageRequest=} page * @param {ExecutionFilters=} filters * @throws {DeferError} when error is unknown * @returns {Promise} */ export declare function listExecutions(page?: PageRequest, filters?: ExecutionFilters): Promise; /** * Enqueue and wait for an execution result * @async * @template F * @param {DeferredFunction} fn * @throws {ExecutionNotFound} when execution does not exists * @throws {ExecutionResultNotAvailableYet} when result is not yet available * @throws {ExecutionResultNotAvailable} when there's no result * @throws {DeferError} when error is unknown * @returns {Promise>} */ export declare function awaitResult>(fn: DeferredFunction): (...args: Parameters) => Promise>;