1.4.2 • Published 10 days ago

@windingtree/sdk-queue v1.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

@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

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

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

Testing

pnpm test

Contributing

Contribution guidelines

1.4.2

10 days ago

1.4.1

1 month ago

1.4.0

2 months ago

1.3.1

2 months ago

1.3.0

3 months ago

1.2.7

3 months ago

1.2.6-beta.0

4 months ago

1.2.6

4 months ago

1.2.5

5 months ago

1.2.4

5 months ago

1.2.3

5 months ago

1.2.2

6 months ago

1.2.1

6 months ago

1.2.0

7 months ago

1.2.0-beta.1

7 months ago

1.2.0-beta.0

9 months ago

1.1.0

10 months ago

1.1.0-beta.3

10 months ago

1.1.0-beta.2

10 months ago

1.1.0-beta.1

10 months ago

1.1.0-beta.0

10 months ago