MCPcopy Create free account
hub / github.com/triggerdotdev/trigger.dev / loader

Function loader

apps/webapp/app/routes/admin.api.v1.snapshot.ts:26–58  ·  view source on GitHub ↗
({ request }: DataFunctionArgs)

Source from the content-addressed store, hash-verified

24}
25
26export async function loader({ request }: DataFunctionArgs) {
27 const user = await requireUser(request);
28
29 if (!user.admin) {
30 throw new Response("You must be an admin to perform this action", { status: 403 });
31 }
32
33 const tempDir = os.tmpdir();
34 const filepath = path.join(
35 tempDir,
36 `${getTaskIdentifier()}-${formatDate(new Date())}.heapsnapshot`
37 );
38
39 const snapshotPath = v8.writeHeapSnapshot(filepath);
40 if (!snapshotPath) {
41 throw new Response("No snapshot saved", { status: 500 });
42 }
43
44 const body = new PassThrough();
45 const stream = fs.createReadStream(snapshotPath);
46 stream.on("open", () => stream.pipe(body));
47 stream.on("error", (err) => body.end(err));
48 stream.on("end", () => body.end());
49
50 return new Response(body as any, {
51 status: 200,
52 headers: {
53 "Content-Type": "application/octet-stream",
54 "Content-Disposition": `attachment; filename="${path.basename(snapshotPath)}"`,
55 "Content-Length": (await fs.promises.stat(snapshotPath)).size.toString(),
56 },
57 });
58}
59
60function getTaskIdentifier() {
61 if (!process.env.ECS_CONTAINER_METADATA_URI) {

Callers

nothing calls this directly

Calls 5

requireUserFunction · 0.90
getTaskIdentifierFunction · 0.85
formatDateFunction · 0.85
toStringMethod · 0.80
onMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…