How to integrate queues with cloudflare workers and hono ? #2282
Unanswered
pullmann4rent
asked this question in
Q&A
Replies: 1 comment
-
import { Hono } from 'hono'
type Environment = {
readonly ERROR_QUEUE: Queue<Error>
readonly ERROR_BUCKET: R2Bucket
}
const app = new Hono<{
Bindings: Environment
}>()
app.get('/', (c) => {
if (Math.random() < 0.5) {
return c.text('Success!')
}
throw new Error('Failed!')
})
app.onError(async (err, c) => {
await c.env.ERROR_QUEUE.send(err)
return c.text(err.message, { status: 500 })
})
export default {
fetch: app.fetch,
async queue(batch: MessageBatch<Error>, env: Environment) {
let file = ''
for (const message of batch.messages) {
const error = message.body
file += error.stack || error.message || String(error)
file += '\r\n'
}
await env.ERROR_BUCKET.put(`errors/${Date.now()}.log`, file)
},
} documentation link: https://hono.dev/snippets/cloudflare-queue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I heard cloudflare workers are not great when using long running functions. So when I use a queue like rabbitmq or kafka and I deploy it on cloudflare workers do I get any problems or does it work ?
Beta Was this translation helpful? Give feedback.
All reactions