MCPcopy Index your code
hub / github.com/cursor/community-plugins / GET

Function GET

apps/cursor/src/app/api/queue/plugin-scans/drain/route.ts:56–159  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

54}
55
56export async function GET(request: NextRequest) {
57 const unauthorized = requireCronAuth(request);
58 if (unauthorized) return unauthorized;
59
60 let msg: Awaited<ReturnType<typeof readNextPluginScan>>;
61 try {
62 msg = await readNextPluginScan(VT_SECONDS);
63 } catch (err) {
64 logError("readNextPluginScan failed", err);
65 return NextResponse.json(
66 { ok: false, error: "queue_read_failed" },
67 { status: 500 },
68 );
69 }
70
71 if (!msg) {
72 return NextResponse.json({
73 ok: true,
74 queue: PLUGIN_SCAN_QUEUE,
75 drained: 0,
76 });
77 }
78
79 const { msg_id, read_ct, message } = msg;
80 const pluginId = message.plugin_id;
81
82 if (!pluginId || typeof pluginId !== "string") {
83 // Malformed payload — archive it so it doesn't keep getting retried.
84 logError(
85 "malformed message; archiving",
86 new Error(JSON.stringify(message)),
87 );
88 await archivePluginScan(msg_id).catch((err) =>
89 logError("archive (malformed) failed", err),
90 );
91 return NextResponse.json(
92 { ok: false, archived: msg_id, reason: "malformed_message" },
93 { status: 200 },
94 );
95 }
96
97 if (read_ct > MAX_ATTEMPTS) {
98 logInfo("exceeded MAX_ATTEMPTS; burying", {
99 pluginId,
100 msg_id,
101 read_ct,
102 max: MAX_ATTEMPTS,
103 });
104 await markScanFailed(pluginId, `Exceeded ${MAX_ATTEMPTS} scan attempts`);
105 await archivePluginScan(msg_id);
106 invalidatePluginCaches();
107 return NextResponse.json({
108 ok: true,
109 buried: pluginId,
110 msg_id,
111 read_ct,
112 });
113 }

Callers

nothing calls this directly

Calls 8

requireCronAuthFunction · 0.90
readNextPluginScanFunction · 0.90
archivePluginScanFunction · 0.90
markScanFailedFunction · 0.90
runPluginScanFunction · 0.90
invalidatePluginCachesFunction · 0.85
logErrorFunction · 0.70
logInfoFunction · 0.70

Tested by

no test coverage detected