workerpool icon indicating copy to clipboard operation
workerpool copied to clipboard

feature request: get active tasks details

Open hlehmann opened this issue 8 years ago • 4 comments

I would like to see what are active tasks.

Is it possible to save main and params in workers->processing. And eventually get them in pool.stats()

hlehmann avatar Oct 15 '17 09:10 hlehmann

Thanks for the suggestion. That could be interesting, I think this will be quite easy and will not introduce any overhead.

I don't think you always have stats() return this list methods/args of all queued and active tasks, since that can cost performance. We could extend the stats method with an option, something like:

Pool.stats({taskContents: true})

and then the response could be:

{
  totalWorkers: 0,
  busyWorkers: 0,
  idleWorkers: 0,
  pendingTasks: 0,
  activeTasks: 0,
  pendingTaskContents: [
    {method: ..., args: [...]},
    ...
  ]
  activeTaskContents: [
    {method: ..., args: [...]},
    ...
  ]
}

would that make sense?

josdejong avatar Oct 16 '17 19:10 josdejong

yes that's seems a good solution.

hlehmann avatar Oct 16 '17 21:10 hlehmann

Thank you josdejong for the great library.

To add on to this request - it'll be really helpful if we can get details of the current tasks either running or queued, so we can avoid creating redundant tasks. Any way to do this already?

fsai-cyuan avatar Jul 25 '18 06:07 fsai-cyuan

What you could do right now is creating some sort of a wrapper around your tasks and keep these statistics yourself:

const myRunningTasks = { }

function myTask() {
  myRunningTasks[myTaskId] = true
  doTheRealWork()
  delete myRunningTasks[myTaskId]
}

josdejong avatar Jul 28 '18 13:07 josdejong