I have an express server that starts a reoccurring job upon client request for a specified amount of time, the issue I'm facing is: How can I stop and remove that specific job after completion.
The code that I have is
// do the request logic
// generate the job ID
// save the job ID with repetition amount in mongoose
bree.add({
name: jobID,
interval : "30s",
path : "./jobs/example_job.js",
worker: {
workerData: {
jobID: jobID,
}},
})
bree.start(jobID)
and for the example_job.js
const thread = require("worker_threads") // for the jobID
// performs some logic
// reduce repetition amount
if(module.repetitionAmout == 0)
{
// delete the mongoose module
// stop the function with name jobID
}
My issue is with // stop the function with name jobID. how can I achieve that? I've tried process.exit(0) but that only exits the thread and doesn't stop it from repeating again I've also tried exporting and importing the bree instance to the example_job.js and passing the jobID to cancel it there but that also did not work, anyone has any experience with canceling jobs?