Does "handled correctly" mean crash the app? (no, seriously) #2308
Answered
by
manast
paulgrieselhuber
asked this question in
Q&A
-
Our app crashes and restarts every time an error is intentionally in a // Setup the message queue
const connection = {
redis: { host: process.env.REDIS_HOST },
};
const queue = new Bull("theJob", connection);
queue.process(async (job, done) => {
const { data: body } = job;
console.log("Doing some work...");
let theThing;
// Load the thing from the db
try {
theThing = await loadTheThing(body);
} catch (error) {
throw new Error("Some error happened", error); // always causes app to crash / restart
}
// Return successfully
done();
});
const handleTheJob = async (ctx) => {
const { request } = ctx;
const { body } = request;
// Add the thing to the processing queue
await queue.add(body, { attempts: 3 });
// We can now return success
ctx.body = { success: true };
};
export default handleTheJob; From the docs it looks like we're doing things properly: imageQueue.process(function (job, done) {
// transcode image asynchronously and report progress
job.progress(42);
// call done when finished
done();
// or give a error if error
done(new Error('error transcoding'));
// or pass it a result
done(null, { width: 1280, height: 720 /* etc... */ });
// If the job throws an unhandled exception it is also handled correctly
throw new Error('some unexpected error');
}); But it occurs to me - what does "handled correctly" mean? I assumed this mean something more like "will tell Bull to retry according to What am I missing? |
Beta Was this translation helpful? Give feedback.
Answered by
manast
Feb 24, 2022
Replies: 1 comment 1 reply
-
You are using the "done" callback and async, you must use one or the other, not both. I recommend you to use async only. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
paulgrieselhuber
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are using the "done" callback and async, you must use one or the other, not both. I recommend you to use async only.