Skip to content

Commit

Permalink
fix: await queue push
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jan 30, 2024
1 parent fa190d9 commit 8f02d44
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/github/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,14 @@ export async function webhookHandler(
payload: payload,
};
if (useQueue) {
logger.info('send to queue');
Environment.instance().Queue.send({
const queueItem = {
botId,
type,
data: webhookEvent,
};
logger.info('send to queue', queueItem);
await Environment.instance().Queue.send(queueItem, {
contentType: 'json',
});
} else {
execContext.waitUntil(webhooks.receive(webhookEvent));
Expand Down
2 changes: 1 addition & 1 deletion src/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ export class QueueConsumer<T> {
export const createConsumer = () => {
const consumer = new QueueConsumer<TQueueMessage>();
consumer.addWorker('github-app', new GitHubAppWorker());
// consumer.addWorker('github-webhook', githubWebhookWorker);
// consumer.addWorker('github-webhook', new GitHubWebHookWorker());
return consumer;
};
8 changes: 5 additions & 3 deletions src/runtime/cfworker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Environment from '@/env';
import { createConsumer } from '@/queue';
import { TQueueMessage } from '@/queue/types';
import { RequiredField } from '@/types';
import { Logger } from '@/utils/logger';

const app = new Hono<{ Bindings: IRuntimeEnv }>() as THono;

Expand All @@ -20,6 +21,7 @@ export default {
env: IRuntimeEnv,
ctx: ExecutionContext,
) {
const logger = Logger.instance();
Environment.from('cfworker', env);

const consumer = createConsumer();
Expand All @@ -29,11 +31,11 @@ export default {
ctx.waitUntil(
consumer
.runAndWait()
.then(() => {
console.log('queue done');
.then((res) => {
logger.info('queue done', res);
})
.catch((err) => {
console.log('queue error', err);
logger.error('queue error', err);
}),
);
},
Expand Down

0 comments on commit 8f02d44

Please sign in to comment.