MCPcopy
hub / github.com/triggerdotdev/trigger.dev / populate

Function populate

apps/webapp/prisma/populate.ts:8–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import { prisma } from "../app/db.server";
7
8async function populate() {
9 if (process.env.NODE_ENV !== "development") {
10 return;
11 }
12
13 const projectRef = getArg("projectRef");
14 if (!projectRef) {
15 throw new Error("projectRef is required");
16 }
17
18 const project = await prisma.project.findUnique({
19 include: {
20 environments: true,
21 },
22 where: {
23 externalRef: projectRef,
24 },
25 });
26 if (!project) {
27 throw new Error("Project not found");
28 }
29
30 const taskIdentifier = getArg("taskIdentifier");
31 if (!taskIdentifier) {
32 throw new Error("taskIdentifier is required");
33 }
34
35 const runCount = parseInt(getArg("runCount") || "100");
36
37 const task = await prisma.backgroundWorkerTask.findFirst({
38 where: {
39 projectId: project.id,
40 slug: taskIdentifier,
41 },
42 orderBy: {
43 createdAt: "desc",
44 },
45 });
46
47 if (!task) {
48 throw new Error("Task not found");
49 }
50
51 const runs = await prisma.taskRun.createMany({
52 data: Array(runCount)
53 .fill(0)
54 .map((_, index) => {
55 const friendlyId = generateFriendlyId("run");
56
57 return {
58 status: "CANCELED",
59 number: index + 1,
60 friendlyId,
61 runtimeEnvironmentId: project.environments[randomIndex(project.environments)].id,
62 projectId: project.id,
63 taskIdentifier,
64 payload: JSON.stringify({ foo: "bar" }),
65 traceId: "traceId",

Callers 1

populate.tsFile · 0.85

Calls 5

generateFriendlyIdFunction · 0.90
getArgFunction · 0.85
ArrayInterface · 0.85
randomIndexFunction · 0.85
logMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…