# @windingtree/sdk-queue

> Jobs queue

Latest version **1.4.2** (published 2024-04-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @windingtree/sdk-queue
pnpm add @windingtree/sdk-queue
yarn add @windingtree/sdk-queue
bun add @windingtree/sdk-queue
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.2 |
| Published | 2024-04-29 |
| First published | 2023-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 137.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Kostiantyn Smyrnov |
| Maintainers | kostysh, kvakes, tomashq |

## Links

- npm: https://www.npmjs.com/package/@windingtree/sdk-queue
- Repository: https://github.com/windingtree/sdk.git#readme
- Homepage: https://github.com/windingtree/sdk/tree/readme#readme
- Issues: https://github.com/windingtree/sdk/issues
- npm.io page: https://npm.io/package/@windingtree/sdk-queue

## Dependencies (6)

- [superjson](https://npm.io/package/superjson.md) ^2.2.1
- [@libp2p/interface](https://npm.io/package/@libp2p/interface.md) ^0.1.3
- [@windingtree/contracts](https://npm.io/package/@windingtree/contracts.md) ^1.0.0
- [@windingtree/sdk-utils](https://npm.io/package/@windingtree/sdk-utils.md) 1.2.3
- [@windingtree/sdk-logger](https://npm.io/package/@windingtree/sdk-logger.md) 1.1.4
- [@windingtree/sdk-storage](https://npm.io/package/@windingtree/sdk-storage.md) 1.5.0

## Recent versions

- 1.4.2 (latest) — 2024-04-29
- 1.2.6-beta.0 (beta) — 2024-01-17
- 1.4.1 — 2024-03-28
- 1.4.0 — 2024-03-20
- 1.3.1 — 2024-03-11
- 1.3.0 — 2024-02-19
- 1.2.7 — 2024-01-26
- 1.2.6 — 2024-01-17
- 1.2.5 — 2023-12-22
- 1.2.4 — 2023-12-11
- 1.2.3 — 2023-11-29
- 1.2.2 — 2023-10-31
- 1.2.1 — 2023-10-31
- 1.2.0 — 2023-10-25
- 1.2.0-beta.1 — 2023-10-25
- … 6 more at https://npm.io/package/@windingtree/sdk-queue/versions

## README

# @windingtree/sdk-queue

This package provides a task queue system designed to manage jobs that need to be executed in an asynchronous, distributed manner.

## Installation

```bash
pnpm i @windingtree/sdk-queue
```

## Key concepts

This library introduces several classes:

1. `Job`: This class represents a job, which is a unit of work that the queue needs to execute. A job has properties like `id`, `handlerName`, `data`, `status`, `isRecurrent`, `recurrenceInterval`, `maxRecurrences`, and `retries`.

2. `JobHandler`: This is a function that a job runs when it's its turn to be executed by the queue.

3. `JobHandlerRegistry`: This class manages job handlers. It allows for registering and retrieving handlers by name.

4. `Queue`: This is the main class of this package. It's responsible for managing and executing jobs.

5. `JobStatus`: An enum representing the different states a job can be in.

## Usage

```typescript
import { Queue, JobConfig } from '@windingtree/sdk-queue';

// Create a new queue
const queue = new Queue({ concurrencyLimit: 5 });

// Register a job handler
queue.registerHandler('myHandler', async (data) => {
  // Process data here
  console.log(data);
  return true;
});

// Create a job config
const jobConfig: JobConfig = {
  handlerName: 'myHandler',
  data: { key: 'value' },
  maxRetries: 3,
};

// Add a job to the queue
const jobId = queue.add(jobConfig);

// You can also get a job
const job = queue.get(jobId);

// Or cancel a job
queue.cancel(jobId);

// Or delete a job
queue.delete(jobId);
```

## Documentation

For full documentation and examples, visit [windingtree.github.io/sdk](https://windingtree.github.io/sdk)

## Testing

```bash
pnpm test
```

## Contributing

[Contribution guidelines](https://windingtree.github.io/sdk/#/docs/contribution)

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