3.0.0 • Published 3 months ago

@averagehelper/job-queue v3.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

job-queue

A simple queue for processing asynchronous tasks sequentially.

Dependencies

This project requires NodeJS (version 16 or later). To make sure you have them available on your machine, try running the following command:

$ node -v
v16.6.2

Installation

$ npm install @averagehelper/job-queue

Usage

import { useJobQueue } from "@averagehelper/job-queue";

// Define your job type
interface Job {
	id: string;
	property1: string;
	property2: string;
}

async function processJob(job: Job): Promise<void> {
	// Do something with your job
}

const queue = useJobQueue<Job>("thing-queue"); // Create or retrieve a job queue
queue.process(processJob); // Add a processor function

// Handle queue event handlers
queue.on("start", () => {
	logger.debug("thing-queue has started processing jobs.");
});

queue.on("error", (error: unknown, failedJob: Job) => {
	logger.debug(`Job ${failedJob.id} failed with error`, error);
});

queue.on("finish", () => {
	logger.debug("thing-queue has finished processing all jobs.");
});

// Add jobs to process
queue.createJob({ property1, property2 });
queue.createJobs([job1, job2]);

Contributing

We welcome contributions of all sorts!

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request :sunglasses:

This project lives primarily at git.average.name. A read-only mirror also exists on GitHub. Issues or pull requests should be filed at git.average.name. You may sign in or create an account directly, or use one of several OAuth 2.0 providers.

Authors

License

MIT

3.0.0

3 months ago

2.1.0

3 months ago

2.0.1

5 months ago

2.0.0

5 months ago

1.0.1

2 years ago

1.0.0

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago