Skip to content

Commit

Permalink
feat(worker): add some log
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Nov 14, 2023
1 parent 6de49d5 commit 665020d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/worker/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export async function queryResourceDetail(ctx: Context<{ Bindings: Env }>) {

const cache = await store.get('' + id);
if (!!cache) {
console.log(`Resouce detail ${id} hit cache`);
return ctx.json({ id, detail: cache });
}

console.log(`Resouce detail ${id} cache miss`);

const db = connect(ctx.env);
const realHref = /^\d+$/.test(href)
? (
Expand All @@ -41,11 +44,15 @@ export async function queryResourceDetail(ctx: Context<{ Bindings: Env }>) {
)[0]?.href
: href;

console.log(`Try fetching dmhy detail of ${realHref}`);

const resp = await fetchDmhyDetail(fetch, realHref);
if (!resp) {
return ctx.json({ message: '404 NOT FOUND' }, 404);
}

console.log(`Set resouce detail ${id} cache`);

// Ignore cache put error
const detail = { ...resp, id };
await store.put('' + id, detail, { expirationTtl: 60 * 60 * 24 * 7 }).catch(() => {});
Expand Down

0 comments on commit 665020d

Please sign in to comment.