Replies: 3 comments
-
Your second statement, starting with |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for the answer! Do you know where can I find documentation on this? When does the job know it should end? Is there any option to make the job open until I manually move it to completed ? I will admit I am having a hard time implementing this. I update the code but the completed event is still triggered before any progress. const worker = new Worker('downloads', async job => {
fetch(job.data.url).
then(responseStream => {
new Promise((resolve, reject) => {
responseStream.body
.pipe(ndjson.parse())
.on('data', async current => {
const game = await generateGame(currentGame);
await game.populate('user');
await game.save()
})
.on('end', resolve)
.on('error', reject);
})
.then(() => {
console.log(`end`);
})
.catch(error => {
console.error(error);
});
});
},
{connection},
); |
Beta Was this translation helpful? Give feedback.
-
You are still not returning the promise, try this: const worker = new Worker(
"downloads",
async (job) =>
fetch(job.data.url).then((responseStream) =>
new Promise((resolve, reject) => {
responseStream.body
.pipe(ndjson.parse())
.on("data", async (current) => {
const game = await generateGame(currentGame);
await game.populate("user");
await game.save();
})
.on("end", resolve)
.on("error", reject);
})
),
{ connection }
); |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to fetch a large amount of data and thought to use bull to help handling it.
I am quite new to bull but you will find below roughly how I dit it.
However, the job is moved to complete when the fetch action is done.
The job will then pipe the stream and process the data.
Beta Was this translation helpful? Give feedback.
All reactions