0.2.6 • Published 6 months ago

simple-js-task-queue v0.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

⚠️ Deprecation Notice: This package has been renamed to taskon. The simple-js-task-queue package is now in legacy mode and will no longer receive regular updates or feature improvements. Only critical bug fixes will be applied to this package if any major bugs are found.

Migration Guide

To migrate to taskon, follow these simple steps:

  1. Install the new package:
yarn add taskon
# or
npm install taskon
  1. Update your imports:
- import { TaskQueue } from 'simple-js-task-queue';
+ import { TaskQueue } from 'taskon';

That's it! No other code changes are needed as taskon maintains full API compatibility.

Table of Contents

Introduction

This lightweight, error-tolerant, no-dependency library provides a sophisticated taks queue management system designed for TypeScript and JavaScript applications, providing advanced functionalities for managing, executing, and monitoring synchronous and asynchronous tasks.

Features

  • Advanced Task Management: Efficiently manage tasks with customizable priorities and statuses.
  • Concurrency Control: Fine-tune the execution of tasks with dynamic concurrency settings.
  • Error Handling: Comprehensive options for error management including retry mechanisms.
  • Integrated Logging: Leverage built-in logging for easy monitoring and debugging.
  • Flexible Task Prioritization: Utilize various prioritization strategies to control task execution order.

Installation

yarn add simple-js-task-queue

Or

npm install simple-js-task-queue

Demo

Check out this codesanbox project!

Usage

Below is a simple example demonstrating how to use the TaskQueue to add and execute a task:

import { TaskQueue } from 'simple-js-task-queue';

const queue = new TaskQueue();

queue
  .addTask(async () => {
    console.log('Performing a task...');
    // Task implementation
  })
  .then((result) => {
    console.log('Task completed.');
  });

API Reference

TaskQueue Class

The TaskQueue class is at the core of the library, offering a rich set of methods to manage tasks:

Method NameDescriptionParameters
addTaskAdds a new task to the queue.callback, onStatusUpdate?, priority?
addPrioritizedTaskAdds a high-priority task to the queue.callback, onStatusUpdate?
addTasksBulk addition of tasks.tasks
adjustConcurrencyAdjusts the number of tasks that can run concurrently, effective instantly.newConcurrency
startStarts or resumes task execution.
stopPauses task execution.
retryRetries failed tasks.
subscribeTaskStatusChangeSubscribes to task status updates.onTaskStatusUpdate
unsubscribeTaskStatusChangeUnsubscribes from task status updates.onTaskStatusUpdate
getTaskDetailsFetches details of a specific task.taskId
getAllTasksDetailsRetrieves details of all tasks, optionally filtered by status.status?
getConcurrencyFetches the concurrency of the task queue.
isManuallyStoppedChecks if the task queue is manually stopped.
clearTaskDetailsClears details of a specific task.taskId
clearAllTasksDetailsRemoves details of all tasks from memory.
clearFailedRetryableTasksClears the list of failed tasks marked for retry.
clearWaitedTasksRemoves all tasks waiting to be executed.
removeFailedRetryableTaskRemoves a specific task from the retry list.taskIdOrTask
removeWaitedTaskRemoves a specific task from the waiting list.taskIdOrTask

License

This library is MIT licensed.

0.2.6

6 months ago

0.2.3

8 months ago

0.2.5

6 months ago

0.2.4

8 months ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.7

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago