Clear runningTasks/Queued Tasks
It would be better if there was an option to cancel runningTasks and also an option to empty the queue
Hey @aya1337,
sorry, didn't get around to respond. I guess you are talking about the pool.
Can you describe in a little more detail what that method(s) would look like / what behavior you would expect. Sounds like you want a pool.cancelAll() method.
@andywer Pretty much methods like:
<pool>.clearQueue() would clear the entire pool queue (tasks that are still waiting for a worker to be free)
<pool>.cancelTasks() I named it cancelTasks because perhaps if you don't provide any parameter, it can cancel all running Tasks? and you can cancel a specific task by providing its ID?
It would be very helpful because I'm using theads.js in a very large service and sometimes, the tasks never resolve. A way to actually clear things and have everything fresh would be very helpful instead of killing the entire pool and re-establishing it
I guess cancelPending() and cancelAll() would be good names. You can already cancel arbitrary tasks today, but not all of them at once.
I am just wondering if more people have a need for this feature? Also, are you sure that clearing all tasks is the best approach? You could probably just cancel the task that's stuck after some time.
The thing is, some tasks can take longer than others, and the pool has 6/7 workers. And i can't really check which specific task is running on a certain worker and be able to cancel it
And i can't really check which specific task is running on a certain worker and be able to cancel it
I admit it's not super convenient, but can you not do it like that?
async function runJobOnPool(pool, cancelAfterMs = 30000) {
const task = pool.queue(async worker => {
/* ... */
})
let taskCompleted = false
const timeout = setTimeout(() => task.cancel(), cancelAfterMs)
const onTaskSettled = () => {
taskCompleted = true
clearTimeout(timeout)
}
task.then(onTaskSettled, onTaskSettled)
return task
}
Need the feature to cancel runningTask!