You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
thumbsup/src/components/listr-work-queue
Romain 0218f90f38
Add README for ListrWorkQueue component
3 years ago
..
README.md Add README for ListrWorkQueue component 3 years ago
index.js refactor(components): bring ListrWorkQueue into this repo to simplify the build process 6 years ago

README.md

listr-work-queue

Drop-in Listr subclass for tasks that need to be picked from a queue concurrently


About this package

The main difference with the standard concurrent: <count> option is that tasks are only rendered as they get picked up, and disappear once processed.

This component will not be necessary anymore if the following Listr feature request is implemented: #53 Display only the task that is running. When it is, we can simply rely on the concurrent: <count> option and let Listr look after the scheduling / execution of the tasks.


Usage

const Listr = require('listr')
const ListrWorkQueue = require('./listr-work-queue/index.js')

const tasks = new Listr([{
  title: 'Running jobs',
  task: () => new ListrWorkQueue(/* tasks */, {
    concurrent: WORKER_COUNT,
    exitOnError: false
  })
}])

tasks.run().then(() => console.log('Done'))

Jobs

Every job is an object with 2 properties, similar to the standard Listr tasks. The task property must be a Promise. Observables and streams are not supported.

{
  title: 'Job A',
  task: () => new Promise(resolve => setTimeout(resolve, 1000))
}

Options

  • concurrent: the number of workers getting tasks from the queue.
{
	concurrent: os.cpus().length
}
  • exitOnError: whether to stop processing new jobs when one of the jobs fails (default is true). Note that pending tasks will still complete before the process is stopped.
{
	exitOnError: false
}
  • update(): a callback to report on the overall progress. This can be used for example to update the parent task title.
{
  title: 'Running jobs',
  task: (ctx, parent) => new ListrWorkQueue(/* tasks */, {
    update: (completed, total) => {
      parent.title = `Running jobs (${completed}/${total})`
    }
  })
}