Skip to content

Commit 21d679e

Browse files
committed
log the scheduled function in work:start
1 parent c722a3e commit 21d679e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/component/loop.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,19 +560,29 @@ async function beginWork(
560560
if (!work) {
561561
throw new Error("work not found");
562562
}
563-
recordStarted(console, work, lagMs);
564563
const { attempts: attempt, fnHandle, fnArgs, payloadId } = work;
565564
const args = { workId, fnHandle, fnArgs, payloadId, logLevel, attempt };
565+
let scheduleId;
566566
if (work.fnType === "action") {
567-
return ctx.scheduler.runAfter(0, internal.worker.runActionWrapper, args);
567+
scheduleId = await ctx.scheduler.runAfter(
568+
0,
569+
internal.worker.runActionWrapper,
570+
args,
571+
);
568572
} else if (work.fnType === "mutation" || work.fnType === "query") {
569-
return ctx.scheduler.runAfter(0, internal.worker.runMutationWrapper, {
570-
...args,
571-
fnType: work.fnType,
572-
});
573+
scheduleId = await ctx.scheduler.runAfter(
574+
0,
575+
internal.worker.runMutationWrapper,
576+
{
577+
...args,
578+
fnType: work.fnType,
579+
},
580+
);
573581
} else {
574582
throw new Error(`Unexpected fnType ${work.fnType}`);
575583
}
584+
recordStarted(console, work, lagMs, scheduleId);
585+
return scheduleId;
576586
}
577587

578588
/**

src/component/stats.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ export function recordStarted(
3838
console: Logger,
3939
work: Doc<"work">,
4040
lagMs: number,
41+
scheduledFunctionId: Id<"_scheduled_functions">,
4142
) {
4243
console.event("started", {
4344
workId: work._id,
4445
fnName: work.fnName,
4546
enqueuedAt: work._creationTime,
47+
scheduledFunctionId,
4648
startedAt: Date.now(),
4749
startLag: lagMs,
4850
});

0 commit comments

Comments
 (0)