Skip to content

Commit

Permalink
Auto-yielding is skipped for tasks that are no-ops and subtasks
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-aitken committed Jan 16, 2024
1 parent 1b2635a commit 38f5a90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-olives-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---

Don't auto-yield with no-op tasks (e.g. logs) that are subtasks
18 changes: 11 additions & 7 deletions packages/trigger-sdk/src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
);
Expand Down

0 comments on commit 38f5a90

Please sign in to comment.