add run logger base type

This commit is contained in:
nicktrn
2025-04-30 21:44:25 +01:00
parent f62047b84b
commit c3dbb8a249
3 changed files with 28 additions and 4 deletions
@@ -8,7 +8,7 @@ import {
} from "@trigger.dev/core/v3/workers";
import { io, type Socket } from "socket.io-client";
import { RunnerEnv } from "./env.js";
import { RunLogger, SendDebugLogOptions } from "./logger.js";
import { ManagedRunLogger, RunLogger, SendDebugLogOptions } from "./logger.js";
import { EnvObject } from "std-env";
import { RunExecution } from "./execution.js";
import { tryCatch } from "@trigger.dev/core/utils";
@@ -47,7 +47,7 @@ export class ManagedRunController {
projectRef: env.TRIGGER_PROJECT_REF,
});
this.logger = new RunLogger({
this.logger = new ManagedRunLogger({
httpClient: this.httpClient,
env,
});
@@ -14,16 +14,20 @@ export type SendDebugLogOptions = {
print?: boolean;
};
export interface RunLogger {
sendDebugLog(options: SendDebugLogOptions): void;
}
export type RunLoggerOptions = {
httpClient: WorkloadHttpClient;
env: RunnerEnv;
};
export class RunLogger {
export class ManagedRunLogger implements RunLogger {
private readonly httpClient: WorkloadHttpClient;
private readonly env: RunnerEnv;
constructor(private readonly opts: RunLoggerOptions) {
constructor(opts: RunLoggerOptions) {
this.httpClient = opts.httpClient;
this.env = opts.env;
}
@@ -59,3 +63,17 @@ export class RunLogger {
});
}
}
export class ConsoleRunLogger implements RunLogger {
private readonly print: boolean;
constructor(opts: { print?: boolean } = {}) {
this.print = opts.print ?? true;
}
sendDebugLog({ message, properties }: SendDebugLogOptions): void {
if (this.print) {
console.log("[ConsoleLogger]", message, properties);
}
}
}
@@ -75,6 +75,12 @@ export class SnapshotManager {
return this.enqueueSnapshotChange({ type: "suspendable", value: suspendable });
}
/**
* Update the snapshot ID and status without invoking any handlers
*
* @param snapshotId - The ID of the snapshot to update to
* @param status - The status to update to
*/
public updateSnapshot(snapshotId: string, status: TaskRunExecutionStatus) {
// Check if this is an old snapshot
if (snapshotId < this.state.id) {