Skip to content

Commit 54db95d

Browse files
committed
Use createdAt for ordering realtime runs instead of number
1 parent 74f32a4 commit 54db95d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/react-hooks/src/hooks/useRealtime.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ async function processRealtimeBatch<TTask extends AnyTask = AnyTask>(
591591
}
592592
}
593593

594-
// Inserts and then orders by the run number, and ensures that the run is not duplicated
594+
// Inserts and then orders by the run createdAt timestamp, and ensures that the run is not duplicated
595595
function insertRunShapeInOrder<TTask extends AnyTask>(
596596
previousRuns: RealtimeRun<TTask>[],
597597
run: RealtimeRun<TTask>
@@ -601,8 +601,8 @@ function insertRunShapeInOrder<TTask extends AnyTask>(
601601
return previousRuns.map((r) => (r.id === run.id ? run : r));
602602
}
603603

604-
const runNumber = run.number;
605-
const index = previousRuns.findIndex((r) => r.number > runNumber);
604+
const runCreatedAt = run.createdAt;
605+
const index = previousRuns.findIndex((r) => r.createdAt > runCreatedAt);
606606
if (index === -1) {
607607
return [...previousRuns, run];
608608
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { logger, runs, task } from "@trigger.dev/sdk";
2+
3+
export const statusesTest = task({
4+
id: "statuses-test",
5+
run: async () => {
6+
console.log("statusesTest");
7+
},
8+
});
9+
10+
export const subscribeToRun = task({
11+
id: "subscribe-to-run",
12+
run: async (payload: { runId: string }) => {
13+
const subscription = runs.subscribeToRun(payload.runId, {
14+
stopOnCompletion: false,
15+
});
16+
17+
for await (const event of subscription) {
18+
logger.info("run event", { event });
19+
}
20+
},
21+
});
22+
23+
export const retrieveRun = task({
24+
id: "retrieve-run",
25+
run: async (payload: { runId: string }) => {
26+
const run = await runs.retrieve(payload.runId);
27+
logger.info("run", { run });
28+
},
29+
});

0 commit comments

Comments
 (0)