Auto-yielding is skipped for tasks that are no-ops and subtasks

This commit is contained in:
Matt Aitken
2024-01-16 14:01:05 +00:00
parent 1b2635ae4a
commit 38f5a90399
2 changed files with 16 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---
Don't auto-yield with no-op tasks (e.g. logs) that are subtasks
+11 -7
View File
@@ -214,12 +214,12 @@ export class IO {
return new IOLogger(async (level, message, data) => {
let logLevel: LogLevel = "info";
if(data instanceof Error){
if (data instanceof Error) {
data = {
name : data.name,
message : data.message,
stack : data.stack
}
name: data.name,
message: data.message,
stack: data.stack,
};
}
if (Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
@@ -1097,8 +1097,6 @@ export class IO {
options?: RunTaskOptions & { parseOutput?: (output: unknown) => T },
onError?: RunTaskErrorCallback
): Promise<T> {
this.#detectAutoYield("start_task", 500);
const parentId = this._taskStorage.getStore()?.taskId;
if (parentId) {
@@ -1109,6 +1107,12 @@ export class IO {
});
}
//don't auto-yield if it's a no-op and a subtask (e.g. a log inside a task)
const isSubtaskNoop = options?.noop === true && parentId !== undefined;
if (!isSubtaskNoop) {
this.#detectAutoYield("start_task", 500);
}
const idempotencyKey = await generateIdempotencyKey(
[this._id, parentId ?? "", cacheKey].flat()
);