Skip to content

Commit 38fe854

Browse files
committed
Make refreshing a task run process work correctly
1 parent c24f3a5 commit 38fe854

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

packages/cli-v3/src/entryPoints/managed/taskRunProcessProvider.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,17 @@ export class TaskRunProcessProvider {
9090
: "keep-alive disabled",
9191
});
9292

93+
const existingPersistentProcess = this.persistentProcess;
94+
9395
// Clean up old persistent process if it exists
94-
if (this.persistentProcess) {
95-
await this.cleanupPersistentProcess();
96+
if (existingPersistentProcess) {
97+
await this.cleanupProcess(existingPersistentProcess);
9698
}
9799

98-
const newProcess = this.createTaskRunProcess(opts);
99-
return newProcess;
100+
this.persistentProcess = this.createTaskRunProcess(opts);
101+
this.executionCount = 0;
102+
103+
return this.persistentProcess;
100104
}
101105

102106
/**
@@ -160,7 +164,9 @@ export class TaskRunProcessProvider {
160164
*/
161165
cleanup(): void {
162166
if (this.persistentProcess) {
163-
this.cleanupPersistentProcess();
167+
this.sendDebugLog("cleanup() called");
168+
169+
this.cleanupProcess(this.persistentProcess);
164170
}
165171
}
166172

@@ -227,14 +233,11 @@ export class TaskRunProcessProvider {
227233
return process.isPreparedForNextRun || process.isPreparedForNextAttempt;
228234
}
229235

230-
private async cleanupPersistentProcess(): Promise<void> {
231-
if (this.persistentProcess) {
232-
this.sendDebugLog("Cleaning up persistent TaskRunProcess");
236+
private async cleanupProcess(taskRunProcess: TaskRunProcess): Promise<void> {
237+
if (taskRunProcess) {
238+
this.sendDebugLog("Cleaning up TaskRunProcess", { pid: taskRunProcess.pid });
233239

234-
// Don't await this - let it cleanup in the background
235-
await this.persistentProcess.kill("SIGKILL").catch(() => {});
236-
this.persistentProcess = null;
237-
this.executionCount = 0;
240+
await taskRunProcess.kill("SIGKILL").catch(() => {});
238241
}
239242
}
240243

packages/cli-v3/src/executions/taskRunProcess.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ export class TaskRunProcess {
170170

171171
this._childPid = this._child?.pid;
172172

173+
logger.debug("initialized task run process", {
174+
path: workerManifest.workerEntryPoint,
175+
cwd,
176+
pid: this._childPid,
177+
});
178+
173179
this._ipc = new ZodIpcConnection({
174180
listenSchema: ExecutorToWorkerMessageCatalog,
175181
emitSchema: WorkerToExecutorMessageCatalog,
@@ -303,7 +309,7 @@ export class TaskRunProcess {
303309
}
304310

305311
async #handleExit(code: number | null, signal: NodeJS.Signals | null) {
306-
logger.debug("handling child exit", { code, signal });
312+
logger.debug("handling child exit", { code, signal, pid: this.pid });
307313

308314
// Go through all the attempts currently pending and reject them
309315
for (const [id, status] of this._attemptStatuses.entries()) {

references/hello-world/trigger.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { syncEnvVars } from "@trigger.dev/build/extensions/core";
44
export default defineConfig({
55
compatibilityFlags: ["run_engine_v2"],
66
project: "proj_rrkpdguyagvsoktglnod",
7-
experimental_processKeepAlive: true,
7+
experimental_processKeepAlive: {
8+
enabled: true,
9+
maxExecutionsPerProcess: 3,
10+
},
811
logLevel: "log",
912
maxDuration: 3600,
1013
retries: {

0 commit comments

Comments
 (0)