Skip to content

Commit

Permalink
fix: github queue cannot process image
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jun 25, 2024
1 parent 59675fc commit ddb238c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion __tests__/queue/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/api/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export type ContinuationContext = {
ctx: Context<THonoEnvironment>;
};

const { store, get } = asyncLocalStorage<ContinuationContext>();
const { middleware, get } = asyncLocalStorage<ContinuationContext>();

export { store };
export { middleware };

export const context = () => get('ctx');
2 changes: 1 addition & 1 deletion src/api/middleware/async-local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Callback<T, E extends Env> = (c: Context<E>) => T;
export const asyncLocalStorage = <T>() => {
const localStorage = new AsyncLocalStorage<T>();
return {
store: <E extends Env = Env>(callback: Callback<T, E>) =>
middleware: <E extends Env = Env>(callback: Callback<T, E>) =>
createMiddleware(async (c, next) => {
const obj = callback(c);
return localStorage.run(obj, next);
Expand Down
4 changes: 2 additions & 2 deletions src/api/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StatusCode } from 'hono/utils/http-status';

import { store } from '../context';
import { middleware } from '../context';

import * as GitHub from './github';

Expand Down Expand Up @@ -37,7 +37,7 @@ export const enhanceContext = (hono: THono) => {
});

hono.use(
store<THonoEnvironment>((ctx) => ({
middleware<THonoEnvironment>((ctx) => ({
ctx,
})),
);
Expand Down
6 changes: 5 additions & 1 deletion src/github/dingtalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class QueueConsumer<T extends { type: string }> {
}
}

async runAndWait() {
async runAndAwait() {
const promises = [] as Promise<void>[];
for (const w of this.workerMap.values()) {
promises.push(w.run());
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/cfworker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down

0 comments on commit ddb238c

Please sign in to comment.