Skip to content

Commit 2e575a7

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-dequeue-snapshot-batch-ids
2 parents 5e80ba3 + b322cf1 commit 2e575a7

File tree

5 files changed

+98
-9
lines changed

5 files changed

+98
-9
lines changed

apps/webapp/app/components/run/RunTimeline.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,11 @@ export function RunTimelineEvent({
345345
<div className="relative flex flex-col items-center justify-center">
346346
<EventMarker variant={variant} state={state} style={style} />
347347
</div>
348-
<div className="flex items-baseline justify-between gap-3">
348+
<div className="flex min-w-0 items-baseline justify-between gap-3">
349349
<TooltipProvider disableHoverableContent>
350350
<Tooltip>
351-
<TooltipTrigger className="cursor-default">
352-
<span className="font-medium text-text-bright">{title}</span>
351+
<TooltipTrigger className="min-w-0 max-w-full cursor-default text-left">
352+
<div className="truncate font-medium text-text-bright">{title}</div>
353353
</TooltipTrigger>
354354
{helpText && (
355355
<TooltipContent className="flex items-center gap-1 text-xs">
@@ -359,7 +359,9 @@ export function RunTimelineEvent({
359359
</Tooltip>
360360
</TooltipProvider>
361361
{subtitle ? (
362-
<span className="text-xs tabular-nums text-text-dimmed">{subtitle}</span>
362+
<span className="whitespace-nowrap text-xs tabular-nums text-text-dimmed">
363+
{subtitle}
364+
</span>
363365
) : null}
364366
</div>
365367
</div>

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.waitpoints.tokens/route.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ export default function Page() {
163163
token,
164164
filters
165165
);
166+
const rowIsSelected = waitpointParam === token.id;
166167

167168
return (
168-
<TableRow key={token.id}>
169+
<TableRow
170+
key={token.id}
171+
className={rowIsSelected ? "bg-grid-dimmed" : undefined}
172+
>
169173
<TableCell to={path}>
170174
<span className="opacity-60">
171175
<DateTime date={token.createdAt} />
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Note>
2-
In the Trigger.dev Cloud we automatically pause execution of tasks when they are waiting for
3-
longer than a few seconds. You are not charged when execution is paused.
4-
</Note>
1+
In the Trigger.dev Cloud we automatically pause execution of tasks when they are waiting for
2+
longer than a few seconds.
3+
4+
When triggering and waiting for subtasks, the parent is checkpointed and while waiting does not count towards compute usage. When waiting for a time period (`wait.for` or `wait.until`), if the wait is longer than 5 seconds we checkpoint and it does not count towards compute usage.

internal-packages/run-engine/src/engine/systems/checkpointSystem.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ export class CheckpointSystem {
194194
metadata: snapshot.metadata,
195195
},
196196
previousSnapshotId: snapshot.id,
197+
batchId: snapshot.batchId ?? undefined,
198+
completedWaitpoints: snapshot.completedWaitpoints.map((waitpoint) => ({
199+
id: waitpoint.id,
200+
index: waitpoint.index,
201+
})),
197202
environmentId: snapshot.environmentId,
198203
environmentType: snapshot.environmentType,
199204
projectId: snapshot.projectId,

packages/trigger-sdk/src/v3/wait.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ export class WaitpointTimeoutError extends Error {
369369
}
370370
}
371371

372+
const DURATION_WAIT_CHARGE_THRESHOLD_MS = 5000;
373+
374+
function printWaitBelowThreshold() {
375+
console.warn(
376+
`Waits of ${DURATION_WAIT_CHARGE_THRESHOLD_MS / 1000}s or less count towards compute usage.`
377+
);
378+
}
379+
372380
export const wait = {
373381
for: async (options: WaitForOptions) => {
374382
const ctx = taskContext.ctx;
@@ -380,6 +388,36 @@ export const wait = {
380388

381389
const start = Date.now();
382390
const durationInMs = calculateDurationInMs(options);
391+
392+
if (durationInMs <= DURATION_WAIT_CHARGE_THRESHOLD_MS) {
393+
return tracer.startActiveSpan(
394+
`wait.for()`,
395+
async (span) => {
396+
if (durationInMs <= 0) {
397+
return;
398+
}
399+
400+
printWaitBelowThreshold();
401+
402+
await new Promise((resolve) => setTimeout(resolve, durationInMs));
403+
},
404+
{
405+
attributes: {
406+
[SemanticInternalAttributes.STYLE_ICON]: "wait",
407+
...accessoryAttributes({
408+
items: [
409+
{
410+
text: nameForWaitOptions(options),
411+
variant: "normal",
412+
},
413+
],
414+
style: "codepath",
415+
}),
416+
},
417+
}
418+
);
419+
}
420+
383421
const date = new Date(start + durationInMs);
384422
const result = await apiClient.waitForDuration(ctx.run.id, {
385423
date: date,
@@ -417,6 +455,46 @@ export const wait = {
417455
throw new Error("wait.forToken can only be used from inside a task.run()");
418456
}
419457

458+
// Calculate duration in ms
459+
const durationInMs = options.date.getTime() - Date.now();
460+
461+
if (durationInMs <= DURATION_WAIT_CHARGE_THRESHOLD_MS) {
462+
return tracer.startActiveSpan(
463+
`wait.for()`,
464+
async (span) => {
465+
if (durationInMs === 0) {
466+
return;
467+
}
468+
469+
if (durationInMs < 0) {
470+
if (options.throwIfInThePast) {
471+
throw new Error("Date is in the past");
472+
}
473+
474+
return;
475+
}
476+
477+
printWaitBelowThreshold();
478+
479+
await new Promise((resolve) => setTimeout(resolve, durationInMs));
480+
},
481+
{
482+
attributes: {
483+
[SemanticInternalAttributes.STYLE_ICON]: "wait",
484+
...accessoryAttributes({
485+
items: [
486+
{
487+
text: options.date.toISOString(),
488+
variant: "normal",
489+
},
490+
],
491+
style: "codepath",
492+
}),
493+
},
494+
}
495+
);
496+
}
497+
420498
const apiClient = apiClientManager.clientOrThrow();
421499

422500
const result = await apiClient.waitForDuration(ctx.run.id, {

0 commit comments

Comments
 (0)