# lcherone-task-queue

> A simple wrapper for fastq

Latest version **1.0.3** (published 2023-01-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install lcherone-task-queue
pnpm add lcherone-task-queue
yarn add lcherone-task-queue
bun add lcherone-task-queue
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-01-09 |
| First published | 2023-01-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | lcherone |

## Links

- npm: https://www.npmjs.com/package/lcherone-task-queue
- npm.io page: https://npm.io/package/lcherone-task-queue

## Dependencies (1)

- [fastq](https://npm.io/package/fastq.md) ^1.15.0

## Recent versions

- 1.0.3 (latest) — 2023-01-09
- 1.0.1 — 2023-01-07
- 1.0.0 — 2023-01-07

## README

# lcherone-task-queue

This library provides a simple task queue for handling asynchronous tasks. Which uses a basic interval timer and fastq.


## Installation

To install `lcherone-task-queue`, run the following command:

```
npm i lcherone-task-queue
```

## Usage

To use `lcherone-task-queue`, follow these steps:

1. Import the `lcherone-task-queue` library:

```
const Tasks = require('lcherone-task-queue')
```

2. Create a new instance of the `Tasks` class:

```
const tasks = new Tasks()
```

3. Add a new task queue to the `Tasks` instance:

```
tasks.add(
  // Name of the task queue
  'email',
  {
    // The finder function should return a list of jobs as a Promise
    finder: () => {
      return Promise.resolve(Array.from({ length: 10000 }, (_, i) => i + 1))
    },

    // The job worker, gets passed the single item should callback
    worker: function (input, cb) {
      // Log the input to the console
      console.log('worker', input)
      // Call the callback with a null error and the result of the job (in this case, the input multiplied by 2)
      cb(null, input * 2)
    },

    // The success handler, handles if the single job item completed
    onSuccess: (input, result) => {
      // Log the result and input to the console
      console.log('onSuccess', result, input)
    },

    // The error handler, handles if the single job item failed
    onError: (input, err) => {
      // Log the error and input to the console
      console.log('onError', err, input)
    },

    // The interval in ms on when to fire the job finder
    interval: 1000
  }
)
```

4. Run the task queue:

```
tasks.run()
```

## Options

- `finder`: A function that returns a Promise resolving to a list of jobs.
- `worker`: A function that processes a single job item. It should accept two arguments: `input` (the job item) and `cb` (a callback function). The callback should be called with two arguments: `err` (an error if one occurred) and `result` (the result of the job).
- `onSuccess`: A function that is called when a job item is successfully processed. It should accept two arguments: `input` (the job item) and `result` (the result of the job).
- `onError`: A function that is called when an error occurs while processing a job item. It should accept two arguments: `input` (the job item) and `err` (the error).
- `interval`: The interval in milliseconds at which to run the `finder` function.

---
_Source: https://npm.io/package/lcherone-task-queue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
