trigger.dev
Version:
A Command-Line Interface for Trigger.dev projects
144 lines (143 loc) • 4.98 kB
TypeScript
import { WorkerManifest } from "@trigger.dev/core/v3";
import { RunLogger } from "./logger.js";
import { RunnerEnv } from "./env.js";
import { WorkloadHttpClient } from "@trigger.dev/core/v3/workers";
import { Metadata } from "./overrides.js";
import type { SupervisorSocket } from "./controller.js";
import { TaskRunProcessProvider } from "./taskRunProcessProvider.js";
type RunExecutionOptions = {
workerManifest: WorkerManifest;
env: RunnerEnv;
httpClient: WorkloadHttpClient;
logger: RunLogger;
supervisorSocket: SupervisorSocket;
taskRunProcessProvider: TaskRunProcessProvider;
};
type RunExecutionPrepareOptions = {
taskRunEnv: Record<string, string>;
};
type RunExecutionRunOptions = {
runFriendlyId: string;
snapshotFriendlyId: string;
dequeuedAt?: Date;
podScheduledAt?: Date;
isWarmStart?: boolean;
};
export declare class RunExecution {
private id;
private executionAbortController;
private _runFriendlyId?;
private currentAttemptNumber?;
private currentTaskRunEnv?;
private snapshotManager?;
private dequeuedAt?;
private podScheduledAt?;
private readonly workerManifest;
private readonly env;
private readonly httpClient;
private readonly logger;
private restoreCount;
private taskRunProcess?;
private snapshotPoller?;
private lastHeartbeat?;
private isShuttingDown;
private shutdownReason?;
private isCompletingRun;
private ignoreSnapshotChanges;
private supervisorSocket;
private notifier?;
private metadataClient?;
private taskRunProcessProvider;
constructor(opts: RunExecutionOptions);
/**
* Cancels the current execution.
*/
cancel(): Promise<void>;
/**
* Kills the current execution.
*/
kill({ exitExecution }?: {
exitExecution?: boolean;
}): Promise<void>;
shutdown(): Promise<void>;
/**
* Prepares the execution with task run environment variables.
* This should be called before executing, typically after a successful run to prepare for the next one.
*/
prepareForExecution(opts: RunExecutionPrepareOptions): Promise<void>;
private attachTaskRunProcessHandlers;
/**
* Returns true if no run has been started yet and we're prepared for the next run.
*/
get canExecute(): boolean;
/**
* Called by the RunController when it receives a websocket notification
* or when the snapshot poller detects a change.
*
* This is the main entry point for snapshot changes, but processing is deferred to the snapshot manager.
*/
private enqueueSnapshotChangesAndWait;
private processSnapshotChange;
private startAttempt;
/**
* Executes the run. This will return when the execution is complete and we should warm start.
* When this returns, the child process will have been cleaned up.
*/
execute(runOpts: RunExecutionRunOptions): Promise<void>;
private executeRunWrapper;
private executeRun;
private complete;
private handleCompletionResult;
private updateSnapshotAfterCompletion;
private convertAttemptStatusToSnapshotStatus;
private measureExecutionMetrics;
private retryImmediately;
private enableIgnoreSnapshotChanges;
/**
* Restores a suspended execution from PENDING_EXECUTING
*/
private restore;
private exitTaskRunProcessWithoutFailingRun;
/**
* Processes env overrides from the metadata service. Generally called when we're resuming from a suspended state.
*/
processEnvOverrides(reason?: string, shouldPollForSnapshotChanges?: boolean): Promise<{
overrides: Metadata;
runnerIdChanged?: boolean;
supervisorChanged?: boolean;
} | null>;
private onHeartbeat;
private sendDebugLog;
private sendRuntimeDebugLog;
private set suspendable(value);
private set runFriendlyId(value);
get runFriendlyId(): string | undefined;
get currentSnapshotFriendlyId(): string | undefined;
get taskRunEnv(): Record<string, string> | undefined;
get metrics(): {
execution: {
restoreCount: number;
lastHeartbeat: Date | undefined;
};
poller: {
lastPollAt: Date | null;
pollCount: number;
} | undefined;
notifier: {
lastNotificationAt: Date | null;
notificationCount: number;
lastInvalidNotificationAt: Date | null;
invalidNotificationCount: number;
} | undefined;
};
get isAborted(): boolean;
private abortExecution;
private shutdownExecution;
private handleSuspendable;
/**
* Fetches the latest execution data and enqueues snapshot changes. Used by both poller and notification handlers.
* @param source string - where this call originated (e.g. 'poller', 'notification')
*/
fetchAndProcessSnapshotChanges(source: string): Promise<void>;
}
export {};