diff --git a/__tests__/queue/base.test.ts b/__tests__/queue/base.test.ts index f4fc629..818e74f 100644 --- a/__tests__/queue/base.test.ts +++ b/__tests__/queue/base.test.ts @@ -17,7 +17,7 @@ describe('queue consumer', () => { consumer.addWorker('test', wk); consumer.push(...batch.messages); expect(wk.queue.length).toBe(100); - await consumer.runAndWait(); + await consumer.runAndAwait(); }); }); diff --git a/src/api/context.ts b/src/api/context.ts index 82b5b5b..e3747ab 100644 --- a/src/api/context.ts +++ b/src/api/context.ts @@ -6,8 +6,8 @@ export type ContinuationContext = { ctx: Context; }; -const { store, get } = asyncLocalStorage(); +const { middleware, get } = asyncLocalStorage(); -export { store }; +export { middleware }; export const context = () => get('ctx'); diff --git a/src/api/middleware/async-local-storage.ts b/src/api/middleware/async-local-storage.ts index f7baa55..cbca9a1 100644 --- a/src/api/middleware/async-local-storage.ts +++ b/src/api/middleware/async-local-storage.ts @@ -8,7 +8,7 @@ type Callback = (c: Context) => T; export const asyncLocalStorage = () => { const localStorage = new AsyncLocalStorage(); return { - store: (callback: Callback) => + middleware: (callback: Callback) => createMiddleware(async (c, next) => { const obj = callback(c); return localStorage.run(obj, next); diff --git a/src/api/middleware/index.ts b/src/api/middleware/index.ts index 79ec364..98d3973 100644 --- a/src/api/middleware/index.ts +++ b/src/api/middleware/index.ts @@ -1,6 +1,6 @@ import { StatusCode } from 'hono/utils/http-status'; -import { store } from '../context'; +import { middleware } from '../context'; import * as GitHub from './github'; @@ -37,7 +37,7 @@ export const enhanceContext = (hono: THono) => { }); hono.use( - store((ctx) => ({ + middleware((ctx) => ({ ctx, })), ); diff --git a/src/github/dingtalk.ts b/src/github/dingtalk.ts index 391a01f..0fa583d 100644 --- a/src/github/dingtalk.ts +++ b/src/github/dingtalk.ts @@ -35,7 +35,11 @@ function dingSecurityInterception(text: string) { export const createImageProxy = () => { return { handleImageUrl: (url: string) => { - return context().getProxiedUrl(url); + try { + return context().getProxiedUrl(url); + } catch (error) { + return url; + } }, }; }; diff --git a/src/queue/index.ts b/src/queue/index.ts index 8ab99eb..baa625b 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -30,7 +30,7 @@ export class QueueConsumer { } } - async runAndWait() { + async runAndAwait() { const promises = [] as Promise[]; for (const w of this.workerMap.values()) { promises.push(w.run()); diff --git a/src/runtime/cfworker/index.ts b/src/runtime/cfworker/index.ts index 59d2c0e..f748748 100644 --- a/src/runtime/cfworker/index.ts +++ b/src/runtime/cfworker/index.ts @@ -25,10 +25,9 @@ export default { const consumer = createConsumer(); consumer.push(...batch.messages); - ctx.waitUntil( consumer - .runAndWait() + .runAndAwait() .then((res) => { logger.info('queue done', res); })