Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion vtex/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ const runtime = withRuntime<Env, typeof StateSchema>({
tools,
});

// DEBUG PROBE — temporary. If `requestCount` increments across requests, the
// isolate is being reused and module-scope caches in @decocms/runtime should
// stick. If it always reads `1`, Workers is spawning a fresh isolate per
// request and the runtime's tools/list cache can never hit. Logs are printed
// before and after the runtime fetch, with timing.
const isolateBootedAt = Date.now();
let requestCount = 0;

export default {
fetch: runtime.fetch,
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
const myReq = ++requestCount;
const t0 = Date.now();
console.log(
`[vtex-probe] req#${myReq} isolateAge=${t0 - isolateBootedAt}ms url=${new URL(req.url).pathname}`,
);
try {
const res = await runtime.fetch(req, env, ctx);
console.log(
`[vtex-probe] req#${myReq} done status=${res.status} ms=${Date.now() - t0}`,
);
return res;
} catch (err) {
console.log(
`[vtex-probe] req#${myReq} threw after ${Date.now() - t0}ms`,
err,
);
throw err;
}
},
};
Loading