Skip to content

Commit e97704d

Browse files
nicktrnmatt-aitken
andauthored
Run Engine 2.0 (WIP) (#1575)
* bump worker version * Suggested glossary for the RunEngine, TBC * Removed BatchTaskRun changes from this branch, they were done in main * Set the BatchTaskRun status to completed when all runs are completed * When dequeuing respect passed in maxResources * Ported over the new run props: idempotencyKeyExpiresAt, versions, oneTimeUseToken, maxDurationInSeconds * Didn’t hit save… the new props when triggering tasks passed through * Idempotency expiration + waitpoint edge case * WIP on creating checkpoint, parking for now * fix worker routes * upgrade webapp node types to support generic event emitter * separate event bus handler singleton and run failure alerts * duration waits * fix execution snapshot debug spans * task waits * fix event bus types * temporary fix for react hook run handle type * disable run notifications for now * convert any typecasts to expect errors to more easily fix later * fix webapp types after node types upgrade * updateEnvConcurrencyLimits across marqs and the runqueue * Pass proper values into the run engine * RunQueue settings and removed unused rebalancing workers * Remove rebalancing prop * Tidied more things up * Update/remove queue limits for MARQS and RunQueue * taskQueue/concurrencyLimit changes ported back into the RunEngine * Reworked completing waitpoints to improve performance and reduce race conditions * Improved test robustness * Down to a single run lock only when a run is totally unblocked and ready to continue * warm starts, worker notifications, wait fixes * Fix for Run Engine poll interval env var * Expect the waitpoint to be completed quickly * If a run is locked then it’s too late to expire it * Added VALKEY_ env vars and plugged them into the run engine * Extracted and updated the guard queue function so it can be used when batching * Added logging and universal concurrency changes to trigger task v1 * Added notes back in * Bump @trigger.dev/worker to 3.3.7 * reportInvocationUsage for the runAttemptStarted event * improve execution snapshot span debug span start times * Unfriendly IDs * update lockfile * Created a shared determineEngineVersion function * disable unfinished commands * save new cli config to different location, misc fixes * add basic engine version check via current deploy * new run engine will default to node 22 runtime * block some actions for projects on previous run engine * fix worker group tests * fix triggerAndWait test * one typescript version to rule them all * redlock type patch * fix type issues caused by ts-reset * improve cleanup scripts * add missing socket.io dep * fix run notification handler type * fix worker group test again * generate prisma client for e2e tests * remove worker group tests for now * prevent image pull rate limits during unit tests * increase timeout for queue concurrency limit test * generate prisma client for preview release * same node types everywhere * Updated engine readme, removed legacy system notes * use default machine preset from platform package * worker instances plural in schema * disable pnpm update notifications * return worker group details from connect call * add workers admin route * fix heartbeat route return type * move deployment labels to core apps * refactor run controller env schema * Add firstAttemptStartedAt to TaskRun * RunEngine 2.0 batch trigger support (#1581) * Make it clear when BatchTriggerV2Service is used * Copy of BatchTriggerV2Service * WIP batch triggering * Allow blocking a run with multiple waitpoints at once. Made it atomic * Removed unused param * New batch service * Pass through the parentRunId and resumeParentOnCompletion * Use the new batch service, and correct trigger task version * Force V1 engine if using BatchTriggerV2Service, we’ve already done the check at this point * Removed the $transaction and early exit if nothing changed * Adedd a simple batch task to the hello world reference catalog * Fix for batch waits not working * Added parentRunId in a couple more places * Removed waitForBatch log * Added another parentRunId * Expanded the example to include all the different triggers * More changes to blocking to support continuing after idempotent completed runs * Fix for the wrong type when blocking a run * remove @Map * optimise worker auth query * add engine version header to core api client requests * remove unique constraint for default group id * consolidate migrations * the first managed worker becomes the global default * Debug events off by default, added an admin toggle to show them * worker group name can't be an empty string * add exec helper to core * move machine resources to core * add pre-dequeue callback to determine max resources * optionally skip dequeue * bump worker package * move worker to core * fix ReadableStream type error * fix another type issue * update a few more tsconfigs * add metadata changes introduced in #1563 * Run Engine 2.0 trigger idempotency (#1613) * Return isCached from the trigger API endpoint * Fix for the wrong type when blocking a run * Render the idempotent run in the inspector * Event repository for idempotency * Debug events off by default, added an admin toggle to show them * triggerAndWait idempotency span * Some improvements to the reference idempotency task * Removed the cached tracing from the SDK * Server-side creating cached span * Improved idempotency test task * Create cached task spans in a better way * Idempotency span support inc batch trigger * Simplified how the spans are done, using more of the existing code * Improved the idempotency test task * Added Waitpoint Batch type, add to TaskRunWaitpoint with order * Pass batch ids through to the run engine when triggering * Added batchIndex * Better batch support in the run engine * Added settings to batch trigger service, before major overhaul * Allow the longer run/batch ids in the filters * Changed how batching works, includes breaking changes in CLI * Removed batch idempotency because it gets put on the runs instead * Added `runs` to the batch.retrieve call/API * Set firstAttemptStartedAt when creating the first attempt * Do nothing when receiving a BATCH waitpoint * Some fixes in the new batch trigger service… mostly just passing missing optional params through * Tweaked the idempotency test task for more situations * Only block with a batch if it’s a batchTriggerAndWait… 🤦‍♂️ * Added another case to the idempotency test task: multiple of the same idempotencyKey in a single batch * Support for the same run multiple times in the same batch * Small tweaks * Make sure to complete batches, even if they’re not andWait ones * Export RunDuplicateIdempotencyKeyError from the run engine * Latest lockfile * Trigger with a machine (old run engine) * RE2, allow setting machine when triggering * Fix for new glob patterns * add max run count to dequeue from version route * add worker instance name env var and header * queue consumer pre skip callback * poll for more runs after final execution errors * fix dequeue search param schema * add shortcut to debug switch * expose run engine timeouts as env vars * make warm start durations configurable * add optional status to json reply helper * fix preSkip hook, add debug logs * BLOCKED_BY_WAITPOINTS -> SUSPENDED * exit controller when run suspended * check if already replied before http reply * run controller will wait for next run after the current one is suspended * cancel run button shortcut * minimal event repository environment type * fix update metadata call * run suspension and misc fixes wip * change debug shortcut to shift + D * Started work on the Dev supervisor * Formatting * Fix for bad imports * Before rebuilding SSE * Presence updating from the CLI working via SSE * add worker notification debug logs * send run:stop when exiting run phase * skip current snapshot poll on worker notification * add more logs and route to submit run debug logs * add worker and runner ids to snapshots * improve run notification debug logs * add workload debug log route * misc run controller fixes and refactor * prevent parallel execution of critical functions * update bun to 1.2.1 * WIP with dev dequeuing * Method to convert friendlyIds to non-friendly, do nothing with actual ids * Set the engine on BackgroundWorker, lazily upgrade projects to engine V2 * Runs with ttls were getting immediately expired… oops. * Pass the Waiting for deploy reason through, so we have it on the execution snapshots * Fixed the logic for getting the right background worker for a run * Use the correct ID when dequeuing… * determineEngineVersion is now fully functional * Rate limiter ignores the dev endpoints * Retrieving a batch gives you the runIds * Set a unique version for the RE2 BatchTaskRun * add provisional changeset * The start of dev run execution is working * First dev run working * Moved the dev run controller closer to what Nick did with the managed one * export exec output type * Heartbeat fix: don’t heartbeat if _isHeartbeating == false * Dev runs get notifications, some dev bug fixes * Improved logging or dequeuing * We need to dequeue runs from the latest version too, for triggerAndWait * Ported Eric’s validateWorkerManifest with nicer errors * When flattening an idempotency key if part is undefined, return undefined * Dev logging fixes * Remove sigterm listener * Deprecating workers. Don’t specify a BackgroundWorker when dequeuing an environment * Deleted some old files. Renamed “managed” to “deploy” * When a build finishes, always copy the build dir (otherwise the first one gets trampled on by the 2nd) * Dev master queues should work differently * Deleting old workers * Added debounce function to core * Improvement to canceling * WIP on debounce canceling on socket disconnection * Added environment data to execution snapshots * Dev runs that have stalled get “Canceled” with a reason explaining why * Show CLI messaged when a connection to the platform is lost/restored * Fix TriggerTask after merge * Add trigger task v2 max attempts, replace some findUniques * Port the new queue logic to the run engine * More fixes post-merge * We weren’t setting a `retryConfig` up for the tests… it’s now required * Start the Redis worker inside the Run Engine… 🤦‍♂️ * Trying to make the testcontainers more reliable * Added keyPrefix: "engine:” * Badly placed bracket in trigger task * Better Redis namespacing * Fix for expired run not getting removed from the queue * Don’t create a redis client in the testcontainers, return the redisOptions instead * Cleanup redis client in the run lock tests * Fix for the RunQueue not supporting keyPrefix * Updated more of the RunQueue scripts rebalancing * Trying to make Redis more robust in the tests… * Improved test resiliciency more * Fix for delays (checkpoint check) * Increase the timeout slightly to fix ttl test * Added priority support when triggering * More wip trying to make test containers more reliable * batchTriggerAndWait test is still failing… some wip to try fix it * Fixed redis tests now we’re not providing a client * Separate Redis clients for the run engine worker/queue/runlock * Made the wait for duration test more resilient * Added idempotencyKeyExpiresAt to Waitpoints * Waitpoint timeouts and idempotency expiry * Use finishWaitpoint, removed extra worker job * Added waitpoint idempotency tests * Creating resume tokens is working * Some improvements to the resume tokens * Moved resumeTokens to just be wait functions 🥳 * Delete old RuntimeManagers * Wait for token is working * Better test for the wait tokens * Improved the test task some more * Hide the accessories in the span inspector * WIP on waitpoint inspector * WIP on complete waitpoint form * Span overview panel can be changed based on the entity type * Improved the waitpoint display * WIP on completing waitpoint form * Use the existing CodeBlock for the tip * Style improvements * Complete waitpoint * All waitpoint sidebar variants * Waits now use a pause icon * Durations waits use the API to create/block with a waitpoint, not the runtime * Fix for engine.blockRunWithWaitpoint required org id * Removed old wait code from the run controllers/task run process * Form action for skipping a datetime waitpoint * Move testDockerCheckpoint to a separate core package export (it can’t be bundled on the client) * Fix for glitchy hourglass animation * Completed waitpoints display better * Increase Redis maxRetriesPerRequest to 20 (default) * Completing and skipping waitpoints is working * Remove the database prisma dev command, since we need to use create only now. Updated docs * Added skip timeout, reworked the UI * Tweaked spacing * Added payload limit to waitpoint token completion from dashboard * Test idempotency works on wait.for and wait.until * Moved the worker-actions to /engine/ from /api/ * Moved dev engine endpoints to /engine/ from /api/ * Separate /engine/ rate limiter * Added parallel wait prevention, it’s working for duration waits but not well for triggerAndWait yet * WIP post-merge conflicts * Set taskEventStore column in the new engine * Remove duplicate keys * Post-merge fixes * Fix for span merge layout * Use executedAt instead of firstAttemptStartedAt --------- Co-authored-by: Matt Aitken <matt@mattaitken.com>
1 parent c519a5a commit e97704d

File tree

307 files changed

+31829
-5638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

307 files changed

+31829
-5638
lines changed

.changeset/breezy-turtles-talk.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@trigger.dev/react-hooks": patch
3+
"@trigger.dev/sdk": patch
4+
"trigger.dev": patch
5+
"@trigger.dev/build": patch
6+
"@trigger.dev/core": patch
7+
"@trigger.dev/rsc": patch
8+
---
9+
10+
Run Engine 2.0 (alpha)

.configs/tsconfig.base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es2022",
4-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
4+
"lib": ["ES2022", "DOM", "DOM.Iterable", "DOM.AsyncIterable"],
55
"module": "NodeNext",
66
"moduleResolution": "NodeNext",
77
"moduleDetection": "force",

.github/workflows/e2e.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
- name: 📥 Download deps
3939
run: pnpm install --frozen-lockfile --filter trigger.dev...
4040

41+
- name: 📀 Generate Prisma Client
42+
run: pnpm run generate
43+
4144
- name: 🔧 Build v3 cli monorepo dependencies
4245
run: pnpm run build --filter trigger.dev^...
4346

.github/workflows/unit-tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ jobs:
2424
node-version: 20.11.1
2525
cache: "pnpm"
2626

27+
# ..to avoid rate limits when pulling images
28+
- name: 🐳 Login to DockerHub
29+
uses: docker/login-action@v3
30+
with:
31+
username: ${{ secrets.DOCKERHUB_USERNAME }}
32+
password: ${{ secrets.DOCKERHUB_TOKEN }}
33+
2734
- name: 📥 Download deps
2835
run: pnpm install --frozen-lockfile
2936

.npmrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
link-workspace-packages=false
22
public-hoist-pattern[]=*prisma*
3-
prefer-workspace-packages=true
3+
prefer-workspace-packages=true
4+
update-notifier=false

.vscode/launch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@
133133
"command": "pnpm exec trigger dev",
134134
"cwd": "${workspaceFolder}/references/hello-world",
135135
"sourceMaps": true
136+
},
137+
{
138+
"type": "node-terminal",
139+
"request": "launch",
140+
"name": "Debug RunEngine tests",
141+
"command": "pnpm run test --filter @internal/run-engine",
142+
"cwd": "${workspaceFolder}",
143+
"sourceMaps": true
136144
}
137145
]
138146
}

CONTRIBUTING.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,21 @@ pnpm run db:studio
230230
cd packages/database
231231
```
232232

233-
3. Create and apply the migrations
233+
3. Create a migration
234234

235235
```
236-
pnpm run db:migrate:dev
236+
pnpm run db:migrate:dev:create
237237
```
238238

239-
This creates a migration file and executes the migrations against your database and applies changes to the database schema(s)
239+
This creates a migration file. Check the migration file does only what you want. If you're adding any database indexes they must use `CONCURRENTLY`, otherwise they'll lock the table when executed.
240+
241+
4. Run the migration.
242+
243+
```
244+
pnpm run db:migrate:deploy
245+
pnpm run generate
246+
```
247+
This executes the migrations against your database and applies changes to the database schema(s), and then regenerates the Prisma client.
240248

241249
4. Commit generated migrations as well as changes to the schema.prisma file
242250
5. If you're using VSCode you may need to restart the Typescript server in the webapp to get updated type inference. Open a TypeScript file, then open the Command Palette (View > Command Palette) and run `TypeScript: Restart TS server`.

apps/coordinator/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
"tinyexec": "^0.3.0"
2424
},
2525
"devDependencies": {
26-
"@types/node": "^18",
2726
"dotenv": "^16.4.2",
2827
"esbuild": "^0.19.11",
29-
"tsx": "^4.7.0",
30-
"typescript": "^5.3.3"
28+
"tsx": "^4.7.0"
3129
}
3230
}

apps/coordinator/src/checkpointer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ExponentialBackoff } from "@trigger.dev/core/v3/apps";
2-
import { testDockerCheckpoint } from "@trigger.dev/core/v3/apps";
2+
import { testDockerCheckpoint } from "@trigger.dev/core/v3/checkpoints";
33
import { nanoid } from "nanoid";
44
import fs from "node:fs/promises";
55
import { ChaosMonkey } from "./chaosMonkey";

apps/coordinator/tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"include": ["./src/**/*.ts"],
3-
"exclude": ["node_modules"],
42
"compilerOptions": {
5-
"target": "es2016",
3+
"target": "es2018",
64
"module": "commonjs",
75
"esModuleInterop": true,
86
"resolveJsonModule": true,

apps/docker-provider/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
"execa": "^8.0.1"
2121
},
2222
"devDependencies": {
23-
"@types/node": "^18.19.8",
2423
"dotenv": "^16.4.2",
2524
"esbuild": "^0.19.11",
26-
"tsx": "^4.7.0",
27-
"typescript": "^5.3.3"
25+
"tsx": "^4.7.0"
2826
}
2927
}

apps/docker-provider/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
TaskOperationsRestoreOptions,
88
} from "@trigger.dev/core/v3/apps";
99
import { SimpleLogger } from "@trigger.dev/core/v3/apps";
10-
import { isExecaChildProcess, testDockerCheckpoint } from "@trigger.dev/core/v3/apps";
10+
import { isExecaChildProcess } from "@trigger.dev/core/v3/apps";
11+
import { testDockerCheckpoint } from "@trigger.dev/core/v3/checkpoints";
1112
import { setTimeout } from "node:timers/promises";
1213
import { PostStartCauses, PreStopCauses } from "@trigger.dev/core/v3";
1314

apps/kubernetes-provider/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"devDependencies": {
2424
"dotenv": "^16.4.2",
2525
"esbuild": "^0.19.11",
26-
"tsx": "^4.7.0",
27-
"typescript": "^5.3.3"
26+
"tsx": "^4.7.0"
2827
}
2928
}

apps/kubernetes-provider/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2016",
3+
"target": "es2018",
44
"module": "commonjs",
55
"esModuleInterop": true,
66
"forceConsistentCasingInFileNames": true,

apps/proxy/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
},
1010
"devDependencies": {
1111
"@cloudflare/workers-types": "^4.20240512.0",
12-
"typescript": "^5.0.4",
1312
"wrangler": "^3.57.1"
1413
},
1514
"dependencies": {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useAnimate } from "framer-motion";
2+
import { HourglassIcon } from "lucide-react";
3+
import { useEffect } from "react";
4+
5+
export function AnimatedHourglassIcon({
6+
className,
7+
delay,
8+
}: {
9+
className?: string;
10+
delay?: number;
11+
}) {
12+
const [scope, animate] = useAnimate();
13+
14+
useEffect(() => {
15+
animate(
16+
[
17+
[scope.current, { rotate: 0 }, { duration: 0.7 }],
18+
[scope.current, { rotate: 180 }, { duration: 0.3 }],
19+
[scope.current, { rotate: 180 }, { duration: 0.7 }],
20+
[scope.current, { rotate: 360 }, { duration: 0.3 }],
21+
],
22+
{ repeat: Infinity, delay }
23+
);
24+
}, []);
25+
26+
return <HourglassIcon ref={scope} className={className} />;
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function PauseIcon({ className }: { className?: string }) {
2+
return (
3+
<svg className={className} viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
4+
<path
5+
fillRule="evenodd"
6+
clipRule="evenodd"
7+
d="M0 10C0 4.47715 4.47715 0 10 0C15.5228 0 20 4.47715 20 10C20 15.5228 15.5228 20 10 20C4.47715 20 0 15.5228 0 10ZM6.5 6C6.5 5.44772 6.94772 5 7.5 5C8.05229 5 8.5 5.44772 8.5 6V14C8.5 14.5523 8.05229 15 7.5 15C6.94772 15 6.5 14.5523 6.5 14V6ZM12.5 5C11.9477 5 11.5 5.44772 11.5 6V14C11.5 14.5523 11.9477 15 12.5 15C13.0523 15 13.5 14.5523 13.5 14V6C13.5 5.44772 13.0523 5 12.5 5Z"
8+
fill="currentColor"
9+
/>
10+
</svg>
11+
);
12+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
export function TaskCachedIcon({ className }: { className?: string }) {
2+
return (
3+
<svg
4+
className={className}
5+
width="16"
6+
height="16"
7+
viewBox="0 0 16 16"
8+
fill="none"
9+
xmlns="http://www.w3.org/2000/svg"
10+
>
11+
<g clipPath="url(#clip0_15584_76102)">
12+
<path
13+
d="M0.5 3.5L0.5 2.5C0.5 1.39543 1.39543 0.5 2.5 0.5H3.5"
14+
stroke="#3B82F6"
15+
strokeLinecap="square"
16+
strokeLinejoin="round"
17+
/>
18+
<path
19+
d="M15.5 12.5L15.5 13.5C15.5 14.6046 14.6046 15.5 13.5 15.5L12.5 15.5"
20+
stroke="#3B82F6"
21+
strokeLinecap="square"
22+
strokeLinejoin="round"
23+
/>
24+
<path
25+
d="M12.5 0.5L13.5 0.5C14.6046 0.5 15.5 1.39543 15.5 2.5L15.5 3.5"
26+
stroke="#3B82F6"
27+
strokeLinecap="square"
28+
strokeLinejoin="round"
29+
/>
30+
<path
31+
d="M3.5 15.5L2.5 15.5C1.39543 15.5 0.5 14.6046 0.5 13.5L0.5 12.5"
32+
stroke="#3B82F6"
33+
strokeLinecap="square"
34+
strokeLinejoin="round"
35+
/>
36+
<path d="M11.1799 4.19V5.598H8.8479V12H7.1649V5.598H4.8219V4.19H11.1799Z" fill="#3B82F6" />
37+
<line x1="6" y1="15.5" x2="10" y2="15.5" stroke="#3B82F6" />
38+
<line x1="6" y1="0.5" x2="10" y2="0.5" stroke="#3B82F6" />
39+
<line x1="15.5" y1="6" x2="15.5" y2="10" stroke="#3B82F6" />
40+
<line x1="0.5" y1="6" x2="0.5" y2="10" stroke="#3B82F6" />
41+
</g>
42+
<defs>
43+
<clipPath id="clip0_15584_76102">
44+
<rect width="16" height="16" fill="white" />
45+
</clipPath>
46+
</defs>
47+
</svg>
48+
);
49+
}

apps/webapp/app/components/code/CodeBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type CodeBlockProps = {
5353
fileName?: string;
5454

5555
/** title text for the Title row */
56-
rowTitle?: string;
56+
rowTitle?: ReactNode;
5757

5858
/** Whether to show the open in modal button */
5959
showOpenInModal?: boolean;

apps/webapp/app/components/primitives/Switch.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as React from "react";
44
import * as SwitchPrimitives from "@radix-ui/react-switch";
55
import { cn } from "~/utils/cn";
6+
import { ShortcutDefinition, useShortcutKeys } from "~/hooks/useShortcutKeys";
67

78
const variations = {
89
large: {
@@ -23,14 +24,34 @@ const variations = {
2324
type SwitchProps = React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root> & {
2425
label?: React.ReactNode;
2526
variant: keyof typeof variations;
27+
shortcut?: ShortcutDefinition;
2628
};
2729

2830
export const Switch = React.forwardRef<React.ElementRef<typeof SwitchPrimitives.Root>, SwitchProps>(
2931
({ className, variant, label, ...props }, ref) => {
32+
const innerRef = React.useRef<HTMLButtonElement>(null);
33+
React.useImperativeHandle(ref, () => innerRef.current as HTMLButtonElement);
34+
3035
const { container, root, thumb, text } = variations[variant];
3136

37+
if (props.shortcut) {
38+
useShortcutKeys({
39+
shortcut: props.shortcut,
40+
action: () => {
41+
if (innerRef.current) {
42+
innerRef.current.click();
43+
}
44+
},
45+
disabled: props.disabled,
46+
});
47+
}
48+
3249
return (
33-
<SwitchPrimitives.Root className={cn("group", container, className)} {...props} ref={ref}>
50+
<SwitchPrimitives.Root
51+
className={cn("group", container, className)}
52+
{...props}
53+
ref={innerRef}
54+
>
3455
{label ? (
3556
<label className={cn("whitespace-nowrap", text)}>
3657
{typeof label === "string" ? <span>{label}</span> : label}

apps/webapp/app/components/runs/v3/BatchFilters.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ function BatchIdDropdown({
359359
if (batchId) {
360360
if (!batchId.startsWith("batch_")) {
361361
error = "Batch IDs start with 'batch_'";
362-
} else if (batchId.length !== 27) {
363-
error = "Batch IDs are 27 characters long";
362+
} else if (batchId.length !== 27 && batchId.length !== 31) {
363+
error = "Batch IDs are 27/32 characters long";
364364
}
365365
}
366366

apps/webapp/app/components/runs/v3/LiveTimer.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,37 @@ export function LiveCountUp({
6666
</>
6767
);
6868
}
69+
70+
export function LiveCountdown({
71+
endTime,
72+
updateInterval = 100,
73+
}: {
74+
endTime: Date;
75+
updateInterval?: number;
76+
}) {
77+
const [now, setNow] = useState<Date>();
78+
79+
useEffect(() => {
80+
const interval = setInterval(() => {
81+
const date = new Date();
82+
setNow(date);
83+
84+
if (date > endTime) {
85+
clearInterval(interval);
86+
}
87+
}, updateInterval);
88+
89+
return () => clearInterval(interval);
90+
}, [endTime]);
91+
92+
return (
93+
<>
94+
{formatDuration(now, endTime, {
95+
style: "short",
96+
maxDecimalPoints: 0,
97+
units: ["d", "h", "m", "s"],
98+
maxUnits: 4,
99+
})}
100+
</>
101+
);
102+
}

apps/webapp/app/components/runs/v3/RunFilters.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,8 @@ function RunIdDropdown({
763763
if (runId) {
764764
if (!runId.startsWith("run_")) {
765765
error = "Run IDs start with 'run_'";
766-
} else if (runId.length !== 25) {
767-
error = "Run IDs are 25 characters long";
766+
} else if (runId.length !== 25 && runId.length !== 29) {
767+
error = "Run IDs are 25/30 characters long";
768768
}
769769
}
770770

0 commit comments

Comments
 (0)