Skip to content

Commit b837b5a

Browse files
committed
Squashed commit of the following:
commit 886429b Author: Matt Aitken <[email protected]> Date: Tue Oct 8 18:36:46 2024 +0100 Removed emails, @trigger.dev/database and @trigger.dev/otlp-importer from changesets config commit f65157a Author: Matt Aitken <[email protected]> Date: Tue Oct 8 18:31:27 2024 +0100 Lockfile with run-engine removed commit 3d67bb8 Author: Matt Aitken <[email protected]> Date: Tue Oct 8 18:24:31 2024 +0100 Removed run-engine from the webapp package.json/tsconfig commit d30e971 Author: Matt Aitken <[email protected]> Date: Tue Oct 8 18:06:04 2024 +0100 Dockerfile fix because the database package has been moved commit f2babbf Author: Matt Aitken <[email protected]> Date: Tue Oct 8 09:41:22 2024 -0700 Internal packages (testcontainers, redis-worker and zod-worker) (#1392) * Some notes on the new run engine * lockfile with setup for the run engine * Documenting where TaskRun is currently mutated, to try figure out the shape of the new system * Added notes about how triggering currently works * Details about when triggering happens * Lots of notes about waitpoints * Started scaffolding the RunEngine * Sketch of Prisma waitpoint schema while it’s fresh in my mind * Got Prisma working with testcontainers * Use beforeEach/afterEach * Simple Prisma and Redis test * Return Redis options instead of a client * Simplified things * A very simple FIFO pull-based queue to check the tests working properly * Use vitest extend * Separate redis, postgres and combined tests for faster testing * Some fixes and test improvements * Pass a logger into the queue * A queue processor that processes items from the given queue as fast as it can * Test for retrying an item that wasn’t processed * First draft of waitpoints in the Prisma schema * Remove the custom logger from the test * Added a completedAt to Waitpoint * Notes on the flow for an execution starting * Added redlock, moved some files around * Starting point for the TaskRunExecutionSnapshot table * Added relationships to TaskRunExecutionSnapshot * Change some tsconfig * Moved some things around * Added some packages * WIP on the RunQueue * Fix for some imports * Key producer with some tests * Removed the nv type from the keys… it’s not useful to do global queries * Passing unit tests for all the public key producer functions * Some basic tests passing for the RunQueue * Simple enqueue test working * Enqueue and dequeue for dev is working * Don’t log everything during the tests * Enqueuing/dequeuing from the shared queue is working * Tests for getting a shared queue * The key producer sharedQueue can now be named, to allow multiple separate queues * The key producer uses the name of the queue as the input * Extra info in the Prisma schema * Dequeuing a message gets the payload and sets the task concurrency all in one Lua script * Adding more keys so we can read the concurrency from the queue * Setting the concurrency with dequeue and enquque is working * Improved the tests and fixed some bugs * Acking is resetting the concurrencies * Check the key has been removed after acking * Nacking is working * Changed the package to CommonJS + Node10 so it works with Redlock * Moved the database, otel and emails packages to be in internal-packages * Moved some Prisma code to the database package * Started using the RunEngine for triggering * Progress on run engine triggering, first waitpoint code * Create a delay waitpoint * Moved ZodWorker to an internal package so it can be used in the run engine as well as the webapp * Web app now uses the zod worker package * Added parseNaturalLanguageDuration to core/apps * internal-packages/zod-worker in the lockfile * Pass in the master queue, remove old rebalance workers code * Add masterQueue to TaskRun * Fixed the tests * Moved waitpoint code into the run engine, also the zod worker * Completing waitpoints * An experiment to create a new test container with environment * More changes to triggering * Started testing triggering * Test for a run getting triggered and being enqueued * Removed dequeueMessageInEnv * Update dev queue tests to use the shared queue function * Schema changes for TaskRunExecutionSnapshot * First execution snapshot when the run is created. Dequeue run function added to the engine * Separate internal package for testcontainers so they can be used elsewhere * Remove the simple queue and testcontainers from the run-engine. They’re going to be separate * Fix for the wrong path to the Prisma schem,a * Added the testcontainers package to the run-engine * redis-worker package, just a copy of the simple queue for now * The queue now uses Lua to enqueue dequeue * The queue now has a catalog and an invisible period after dequeuing * Added a visibility timeout and acking, with tests * Added more Redis connection logging, deleted todos * Visibility timeouts are now defined on the catalog and can be overridden when enqueuing * Dequeue multiple items at once * Test for dequeuing multiple items * Export some types to be used elsewhere * Partial refactor of the processor * First stab at a worker with concurrency and NodeWorkers * Don’t have a default visibility timeout in the queue * Worker setup and processing items in a simple test * Process jobs in parallel with retrying * Get the attempt when dequeuing * Workers do exponential backoff * Moved todos * DLQ functionality * DLQ tests * Same cluster for all keys in the same queue * Added DLQ tests * Whitespace * Redis pubsub to redrive from the worker * Fixed database paths * Fix for path to zod-worker * Fixes for typecheck errors, mostly with TS versions and module resolution * Redlock required a patch * Moved the new DB migrations to the new database package folder * Remove the run-engine package * Remove the RunEngine prisma schema changes * Delete triggerTaskV2 * Remove zodworker test script (no tests) * Update test-containers readme * Generate the client first * Use a specific version of the prisma package * Generate the prisma client before running the unit tests commit fc60947 Author: Dan <[email protected]> Date: Tue Oct 8 14:36:03 2024 +0100 Supabase database webhook example upgrade (#1386) * Added overview for guides and examples section and split them all out * New supabase guide wip * Updated images and improved docs * Trimmed the supabase prereqs * Supabase guide wip * more updates * Replaced old database webhook guide * Created one intro page and removed snippets * Updated guide sidebar titles * Code updates * More improvements * Updates and added images * Compressed image * Updated guides descriptions and edge function basic * Removed bold * Updated redirects * Fixed broken links * Updated intro commit 07f82ea Author: nicktrn <[email protected]> Date: Tue Oct 8 13:28:54 2024 +0100 Release 3.0.11 commit 13ebfcc Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue Oct 8 13:24:38 2024 +0100 chore: Update version for release (#1381) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> commit 2a04d17 Author: nicktrn <[email protected]> Date: Tue Oct 8 09:24:23 2024 +0100 Simplify showLogs expression commit 002ae4b Author: nicktrn <[email protected]> Date: Tue Oct 8 09:22:29 2024 +0100 Fix dotenv overrides for dev runs (#1388) * override dashboard dev env vars with local .env * add changeset * add simple task for testing env vars commit 047cb00 Author: nicktrn <[email protected]> Date: Tue Oct 8 09:22:05 2024 +0100 Disable schedules for deleted orgs on next tick (#1383) * disable schedules for deleted orgs * add debug logs commit 2c014f7 Author: James Ritchie <[email protected]> Date: Sun Oct 6 13:02:00 2024 -0700 Override log retention (#1385) * set full log retention as admin * If run.logsDeletedAt is set, don’t bother getting the trace commit a69e04f Author: nicktrn <[email protected]> Date: Sat Oct 5 14:18:58 2024 +0100 Include push output in logs for self-hosted deploys (#1382) * include push output in logs * changeset commit c5488df Author: nicktrn <[email protected]> Date: Sat Oct 5 13:12:47 2024 +0100 Fix CLI downgrade check (#1380) * fix downgrade detection * remove unused semver package from webapp * add changeset commit 1caec27 Author: Eric Allam <[email protected]> Date: Fri Oct 4 15:33:35 2024 -0700 docs: Max duration (#1379) * maxDuration docs * Update the init command to set the maxDuration and include a commented out maxDuration in the config file commit e14c954 Author: Eric Allam <[email protected]> Date: Fri Oct 4 15:02:05 2024 -0700 Release 3.0.10 commit 8e61f5d Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri Oct 4 14:59:07 2024 -0700 chore: Update version for release (#1378) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> commit 08db565 Author: Eric Allam <[email protected]> Date: Thu Oct 3 12:38:25 2024 -0700 improve the timed out description commit 6d08842 Author: Eric Allam <[email protected]> Date: Thu Oct 3 12:43:26 2024 -0700 feat: Add maxDuration to tasks (#1377) * WIP * Get max duration working on deployed runs * Actually set the timed out runs to status = TIMED_OUT * The client status for TIMED_OUT is now MAX_DURATION_EXCEEDED * New TimedOutIcon * Added new timedout icon * Add ability to opt-out of maxDuration with timeout.None * MAX_DURATION_EXCEEDED -> TIMED_OUT * changeset * Improved styling for the status tooltip content --------- Co-authored-by: James Ritchie <[email protected]> commit 665ccf8 Author: nicktrn <[email protected]> Date: Thu Oct 3 12:33:18 2024 +0100 Update github actions and self-hosting docs commit 1ff7b86 Author: Eric Allam <[email protected]> Date: Wed Oct 2 18:26:36 2024 -0700 Add max queue depth limits (#1376) * Add runs to an env queue, as well as the actual queue * Add queue size limit guard on triggering tasks commit c531a9d Author: Eric Allam <[email protected]> Date: Wed Oct 2 15:30:39 2024 -0700 fix: cleanup ttl expire run graphile jobs (#1373) * fix: remove ttl expire run graphile jobs when a run is started or completed * Update expireEnqueuedRun.server.ts commit 0bf500f Author: Matt Aitken <[email protected]> Date: Wed Oct 2 15:30:16 2024 -0700 Prioritize finishing waited runs (#1375) * If a tree node is missing, estimate the size as zero * Task to test prioritizing finishing existing runs after triggerAndWaits * When requeuing a run with a checkpoint, put it in the queue with the parent run time so it’s correctly prioritized * The same change but if there’s no checkpoint
1 parent 9adffd1 commit b837b5a

File tree

756 files changed

+4620
-1436
lines changed

Some content is hidden

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

756 files changed

+4620
-1436
lines changed

.changeset/config.json

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,13 @@
77
}
88
],
99
"commit": false,
10-
"fixed": [
11-
[
12-
"@trigger.dev/*",
13-
"trigger.dev"
14-
]
15-
],
10+
"fixed": [["@trigger.dev/*", "trigger.dev"]],
1611
"linked": [],
1712
"access": "public",
1813
"baseBranch": "main",
1914
"updateInternalDependencies": "patch",
20-
"ignore": [
21-
"webapp",
22-
"emails",
23-
"proxy",
24-
"@trigger.dev/database",
25-
"coordinator",
26-
"docker-provider",
27-
"kubernetes-provider",
28-
"@trigger.dev/otlp-importer"
29-
],
15+
"ignore": ["webapp", "proxy", "coordinator", "docker-provider", "kubernetes-provider"],
3016
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
3117
"onlyUpdatePeerDependentsWhenOutOfRange": true
3218
}
33-
}
19+
}

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ jobs:
2727
- name: 📥 Download deps
2828
run: pnpm install --frozen-lockfile
2929

30+
- name: 📀 Generate Prisma Client
31+
run: pnpm run generate
32+
3033
- name: 🧪 Run Unit Tests
3134
run: pnpm run test

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "packages/otlp-importer/protos"]
2-
path = packages/otlp-importer/protos
1+
[submodule "internal-packages/otlp-importer/protos"]
2+
path = internal-packages/otlp-importer/protos
33
url = https://github.com/open-telemetry/opentelemetry-proto.git
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function TimedOutIcon({ className }: { className?: string }) {
2+
return (
3+
<svg
4+
className={className}
5+
width="20"
6+
height="20"
7+
viewBox="0 0 20 20"
8+
fill="none"
9+
xmlns="http://www.w3.org/2000/svg"
10+
>
11+
<path
12+
fillRule="evenodd"
13+
clipRule="evenodd"
14+
d="M9 2H8V3H9V4.07089C5.60771 4.55612 3 7.47353 3 11C3 14.866 6.13401 18 10 18C13.866 18 17 14.866 17 11C17 7.47353 14.3923 4.55612 11 4.07089V3H12V2H11H9ZM13.7603 3.36575C14.7218 2.40422 16.2807 2.40422 17.2422 3.36575C18.2038 4.32727 18.2038 5.8862 17.2422 6.84772L17.1462 6.94375C17.1251 6.96488 17.0908 6.96488 17.0697 6.94375L13.6642 3.53831C13.6431 3.51717 13.6431 3.4829 13.6642 3.46177L13.7603 3.36575ZM6.28876 3.58524C6.33584 3.53816 6.33584 3.46184 6.28876 3.41476L6.23971 3.36571C5.27819 2.40419 3.71925 2.40419 2.75773 3.36571C1.79621 4.32723 1.79621 5.88616 2.75773 6.84769L2.80678 6.89674C2.85386 6.94382 2.93019 6.94381 2.97726 6.89674L6.28876 3.58524ZM14.5858 17L16 15.5858L16.7071 16.2929C17.0976 16.6834 17.0976 17.3166 16.7071 17.7071C16.3166 18.0976 15.6834 18.0976 15.2929 17.7071L14.5858 17ZM5.42297 17L4.00875 15.5858L3.30165 16.2929C2.91112 16.6834 2.91112 17.3166 3.30165 17.7071C3.69217 18.0977 4.32534 18.0977 4.71586 17.7071L5.42297 17ZM6.29289 7.29289C6.68342 6.90237 7.31658 6.90237 7.70711 7.29289L10 9.58579L12.2929 7.29289C12.6834 6.90237 13.3166 6.90237 13.7071 7.29289C14.0976 7.68342 14.0976 8.31658 13.7071 8.70711L11.4142 11L13.7071 13.2929C14.0976 13.6834 14.0976 14.3166 13.7071 14.7071C13.3166 15.0976 12.6834 15.0976 12.2929 14.7071L10 12.4142L7.70711 14.7071C7.31658 15.0976 6.68342 15.0976 6.29289 14.7071C5.90237 14.3166 5.90237 13.6834 6.29289 13.2929L8.58579 11L6.29289 8.70711C5.90237 8.31658 5.90237 7.68342 6.29289 7.29289Z"
15+
fill="currentColor"
16+
/>
17+
</svg>
18+
);
19+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ export function SelectPopover({
613613
"z-50 flex flex-col overflow-clip rounded border border-charcoal-700 bg-background-bright shadow-md outline-none animate-in fade-in-40",
614614
"min-w-[max(180px,calc(var(--popover-anchor-width)+0.5rem))]",
615615
"max-w-[min(480px,var(--popover-available-width))]",
616-
"max-h-[min(480px,var(--popover-available-height))]",
616+
"max-h-[min(520px,var(--popover-available-height))]",
617617
"origin-[var(--popover-transform-origin)]",
618618
className
619619
)}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ export function useTree<TData, TFilterValue>({
235235
getItemKey: (index) => state.visibleNodeIds[index],
236236
getScrollElement: () => parentRef.current,
237237
estimateSize: (index: number) => {
238+
const treeItem = tree[index];
239+
if (!treeItem) return 0;
238240
return estimatedRowHeight({
239-
node: tree[index],
240-
state: state.nodes[tree[index].id],
241+
node: treeItem,
242+
state: state.nodes[treeItem.id],
241243
index,
242244
});
243245
},

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ export function RunInspector({
324324
</Property.Value>
325325
</Property.Item>
326326
)}
327+
<Property.Item>
328+
<Property.Label>Max duration</Property.Label>
329+
<Property.Value>
330+
{run.maxDurationInSeconds ? `${run.maxDurationInSeconds}s` : "–"}
331+
</Property.Value>
332+
</Property.Item>
327333
<Property.Item>
328334
<Property.Label>Run invocation cost</Property.Label>
329335
<Property.Value>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import {
88
NoSymbolIcon,
99
PauseCircleIcon,
1010
RectangleStackIcon,
11+
StopIcon,
1112
TrashIcon,
1213
XCircleIcon,
1314
} from "@heroicons/react/20/solid";
1415
import { TaskRunStatus } from "@trigger.dev/database";
1516
import assertNever from "assert-never";
1617
import { SnowflakeIcon } from "lucide-react";
18+
import { TimedOutIcon } from "~/assets/icons/TimedOutIcon";
1719
import { Spinner } from "~/components/primitives/Spinner";
1820
import { cn } from "~/utils/cn";
1921

@@ -27,6 +29,7 @@ export const allTaskRunStatuses = [
2729
"COMPLETED_SUCCESSFULLY",
2830
"CANCELED",
2931
"COMPLETED_WITH_ERRORS",
32+
"TIMED_OUT",
3033
"CRASHED",
3134
"PAUSED",
3235
"INTERRUPTED",
@@ -44,6 +47,7 @@ export const filterableTaskRunStatuses = [
4447
"COMPLETED_SUCCESSFULLY",
4548
"CANCELED",
4649
"COMPLETED_WITH_ERRORS",
50+
"TIMED_OUT",
4751
"CRASHED",
4852
"INTERRUPTED",
4953
"SYSTEM_FAILURE",
@@ -65,6 +69,7 @@ const taskRunStatusDescriptions: Record<TaskRunStatus, string> = {
6569
PAUSED: "Task has been paused by the user",
6670
CRASHED: "Task has crashed and won't be retried",
6771
EXPIRED: "Task has surpassed its ttl and won't be executed",
72+
TIMED_OUT: "Task has failed because it exceeded its maxDuration",
6873
};
6974

7075
export const QUEUED_STATUSES = [
@@ -140,6 +145,8 @@ export function TaskRunStatusIcon({
140145
return <FireIcon className={cn(runStatusClassNameColor(status), className)} />;
141146
case "EXPIRED":
142147
return <TrashIcon className={cn(runStatusClassNameColor(status), className)} />;
148+
case "TIMED_OUT":
149+
return <TimedOutIcon className={cn(runStatusClassNameColor(status), className)} />;
143150

144151
default: {
145152
assertNever(status);
@@ -174,6 +181,8 @@ export function runStatusClassNameColor(status: TaskRunStatus): string {
174181
return "text-error";
175182
case "CRASHED":
176183
return "text-error";
184+
case "TIMED_OUT":
185+
return "text-error";
177186
default: {
178187
assertNever(status);
179188
}
@@ -210,6 +219,8 @@ export function runStatusTitle(status: TaskRunStatus): string {
210219
return "Crashed";
211220
case "EXPIRED":
212221
return "Expired";
222+
case "TIMED_OUT":
223+
return "Timed out";
213224
default: {
214225
assertNever(status);
215226
}

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import { BeakerIcon, BookOpenIcon, CheckIcon } from "@heroicons/react/24/solid";
99
import { useLocation } from "@remix-run/react";
1010
import { formatDuration, formatDurationMilliseconds } from "@trigger.dev/core/v3";
1111
import { useCallback, useRef } from "react";
12+
import { Badge } from "~/components/primitives/Badge";
1213
import { Button, LinkButton } from "~/components/primitives/Buttons";
1314
import { Checkbox } from "~/components/primitives/Checkbox";
1415
import { Dialog, DialogTrigger } from "~/components/primitives/Dialog";
1516
import { Header3 } from "~/components/primitives/Headers";
1617
import { useSelectedItems } from "~/components/primitives/SelectedItemsProvider";
18+
import { SimpleTooltip } from "~/components/primitives/Tooltip";
1719
import { useEnvironments } from "~/hooks/useEnvironments";
1820
import { useFeatures } from "~/hooks/useFeatures";
1921
import { useOrganization } from "~/hooks/useOrganizations";
@@ -39,9 +41,12 @@ import {
3941
import { CancelRunDialog } from "./CancelRunDialog";
4042
import { LiveTimer } from "./LiveTimer";
4143
import { ReplayRunDialog } from "./ReplayRunDialog";
42-
import { TaskRunStatusCombo } from "./TaskRunStatus";
4344
import { RunTag } from "./RunTag";
44-
import { Badge } from "~/components/primitives/Badge";
45+
import {
46+
descriptionForTaskRunStatus,
47+
filterableTaskRunStatuses,
48+
TaskRunStatusCombo,
49+
} from "./TaskRunStatus";
4550

4651
type RunsTableProps = {
4752
total: number;
@@ -126,7 +131,27 @@ export function TaskRunsTable({
126131
<TableHeaderCell>Env</TableHeaderCell>
127132
<TableHeaderCell>Task</TableHeaderCell>
128133
<TableHeaderCell>Version</TableHeaderCell>
129-
<TableHeaderCell>Status</TableHeaderCell>
134+
<TableHeaderCell
135+
tooltip={
136+
<div className="flex flex-col divide-y divide-grid-dimmed">
137+
{filterableTaskRunStatuses.map((status) => (
138+
<div
139+
key={status}
140+
className="grid grid-cols-[8rem_1fr] gap-x-2 py-2 first:pt-1 last:pb-1"
141+
>
142+
<div className="mb-0.5 flex items-center gap-1.5 whitespace-nowrap">
143+
<TaskRunStatusCombo status={status} />
144+
</div>
145+
<Paragraph variant="extra-small" className="!text-wrap text-text-dimmed">
146+
{descriptionForTaskRunStatus(status)}
147+
</Paragraph>
148+
</div>
149+
))}
150+
</div>
151+
}
152+
>
153+
Status
154+
</TableHeaderCell>
130155
<TableHeaderCell>Started</TableHeaderCell>
131156
<TableHeaderCell
132157
colSpan={3}
@@ -287,7 +312,11 @@ export function TaskRunsTable({
287312
</TableCell>
288313
<TableCell to={path}>{run.version ?? "–"}</TableCell>
289314
<TableCell to={path}>
290-
<TaskRunStatusCombo status={run.status} />
315+
<SimpleTooltip
316+
content={descriptionForTaskRunStatus(run.status)}
317+
disableHoverableContent
318+
button={<TaskRunStatusCombo status={run.status} />}
319+
/>
291320
</TableCell>
292321
<TableCell to={path}>
293322
{run.startedAt ? <DateTime date={run.startedAt} /> : "–"}

apps/webapp/app/database-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const TaskRunStatus = {
4242
CRASHED: "CRASHED",
4343
DELAYED: "DELAYED",
4444
EXPIRED: "EXPIRED",
45+
TIMED_OUT: "TIMED_OUT",
4546
} as const satisfies Record<TaskRunStatusType, TaskRunStatusType>;
4647

4748
export const JobRunStatus = {

apps/webapp/app/db.server.ts

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,51 @@
1-
import { Prisma, PrismaClient } from "@trigger.dev/database";
1+
import {
2+
Prisma,
3+
PrismaClient,
4+
PrismaClientOrTransaction,
5+
PrismaReplicaClient,
6+
PrismaTransactionClient,
7+
PrismaTransactionOptions,
8+
} from "@trigger.dev/database";
29
import invariant from "tiny-invariant";
310
import { z } from "zod";
411
import { env } from "./env.server";
512
import { logger } from "./services/logger.server";
613
import { isValidDatabaseUrl } from "./utils/db";
714
import { singleton } from "./utils/singleton";
15+
import { $transaction as transac } from "@trigger.dev/database";
816

9-
export type PrismaTransactionClient = Omit<
10-
PrismaClient,
11-
"$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends"
12-
>;
13-
14-
export type PrismaClientOrTransaction = PrismaClient | PrismaTransactionClient;
15-
16-
function isTransactionClient(prisma: PrismaClientOrTransaction): prisma is PrismaTransactionClient {
17-
return !("$transaction" in prisma);
18-
}
19-
20-
function isPrismaKnownError(error: unknown): error is Prisma.PrismaClientKnownRequestError {
21-
return (
22-
typeof error === "object" && error !== null && "code" in error && typeof error.code === "string"
23-
);
24-
}
25-
26-
export type PrismaTransactionOptions = {
27-
/** The maximum amount of time (in ms) Prisma Client will wait to acquire a transaction from the database. The default value is 2000ms. */
28-
maxWait?: number;
29-
30-
/** The maximum amount of time (in ms) the interactive transaction can run before being canceled and rolled back. The default value is 5000ms. */
31-
timeout?: number;
32-
33-
/** Sets the transaction isolation level. By default this is set to the value currently configured in your database. */
34-
isolationLevel?: Prisma.TransactionIsolationLevel;
35-
36-
swallowPrismaErrors?: boolean;
17+
export type {
18+
PrismaTransactionClient,
19+
PrismaClientOrTransaction,
20+
PrismaTransactionOptions,
21+
PrismaReplicaClient,
3722
};
3823

3924
export async function $transaction<R>(
4025
prisma: PrismaClientOrTransaction,
4126
fn: (prisma: PrismaTransactionClient) => Promise<R>,
4227
options?: PrismaTransactionOptions
4328
): Promise<R | undefined> {
44-
if (isTransactionClient(prisma)) {
45-
return fn(prisma);
46-
}
47-
48-
try {
49-
return await (prisma as PrismaClient).$transaction(fn, options);
50-
} catch (error) {
51-
if (isPrismaKnownError(error)) {
29+
return transac(
30+
prisma,
31+
fn,
32+
(error) => {
5233
logger.error("prisma.$transaction error", {
5334
code: error.code,
5435
meta: error.meta,
5536
stack: error.stack,
5637
message: error.message,
5738
name: error.name,
5839
});
59-
60-
if (options?.swallowPrismaErrors) {
61-
return;
62-
}
63-
}
64-
65-
throw error;
66-
}
40+
},
41+
options
42+
);
6743
}
6844

6945
export { Prisma };
7046

7147
export const prisma = singleton("prisma", getClient);
7248

73-
export type PrismaReplicaClient = Omit<PrismaClient, "$transaction">;
74-
7549
export const $replica: PrismaReplicaClient = singleton(
7650
"replica",
7751
() => getReplicaClient() ?? prisma

apps/webapp/app/env.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ const EnvironmentSchema = z.object({
213213
TASK_PAYLOAD_OFFLOAD_THRESHOLD: z.coerce.number().int().default(524_288), // 512KB
214214
TASK_PAYLOAD_MAXIMUM_SIZE: z.coerce.number().int().default(3_145_728), // 3MB
215215
TASK_RUN_METADATA_MAXIMUM_SIZE: z.coerce.number().int().default(4_096), // 4KB
216+
217+
MAXIMUM_DEV_QUEUE_SIZE: z.coerce.number().int().optional(),
218+
MAXIMUM_DEPLOYED_QUEUE_SIZE: z.coerce.number().int().optional(),
216219
});
217220

218221
export type Environment = z.infer<typeof EnvironmentSchema>;

apps/webapp/app/models/taskRun.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export function batchTaskRunItemStatusForRunStatus(
119119
case TaskRunStatus.SYSTEM_FAILURE:
120120
case TaskRunStatus.CRASHED:
121121
case TaskRunStatus.EXPIRED:
122+
case TaskRunStatus.TIMED_OUT:
122123
return BatchTaskRunItemStatus.FAILED;
123124
case TaskRunStatus.PENDING:
124125
case TaskRunStatus.WAITING_FOR_DEPLOY:

apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ export class ApiRetrieveRunPresenter extends BasePresenter {
270270
case "EXPIRED": {
271271
return "EXPIRED";
272272
}
273+
case "TIMED_OUT": {
274+
return "TIMED_OUT";
275+
}
273276
default: {
274277
assertNever(status);
275278
}

apps/webapp/app/presenters/v3/ApiRunListPresenter.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ export class ApiRunListPresenter extends BasePresenter {
310310
case "EXPIRED": {
311311
return "EXPIRED";
312312
}
313+
case "TIMED_OUT": {
314+
return "TIMED_OUT";
315+
}
313316
default: {
314317
assertNever(status);
315318
}

0 commit comments

Comments
 (0)