https://github.com/lilbunnyrabbit/task-manager
System for managing and executing asynchronous and synchronous tasks with queuing, parallel execution, and progress tracking.
https://github.com/lilbunnyrabbit/task-manager
async-tasks npm-package parallel-execution task-manager task-queue typescript-library typescrpt
Last synced: 15 days ago
JSON representation
System for managing and executing asynchronous and synchronous tasks with queuing, parallel execution, and progress tracking.
- Host: GitHub
- URL: https://github.com/lilbunnyrabbit/task-manager
- Owner: lilBunnyRabbit
- License: mit
- Created: 2024-03-08T23:24:53.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-18T22:27:37.000Z (2 months ago)
- Last Synced: 2025-04-14T00:15:32.817Z (15 days ago)
- Topics: async-tasks, npm-package, parallel-execution, task-manager, task-queue, typescript-library, typescrpt
- Language: HTML
- Homepage: https://lilbunnyrabbit.github.io/task-manager
- Size: 827 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# [TypeScript Task Manager](https://lilbunnyrabbit.github.io/task-manager)
[](https://www.npmjs.com/package/@lilbunnyrabbit/task-manager)
[](https://www.npmjs.com/package/@lilbunnyrabbit/task-manager)A flexible and powerful task management system built with [TypeScript](https://www.typescriptlang.org/). It helps in managing both **synchronous** and **asynchronous** tasks with ease, allowing you to queue tasks, execute them **sequentially** or **in parallel**, and monitor their progress.
> **β¨ Check out the [Landing Page](https://lilbunnyrabbit.github.io/task-manager) for an Overview, Examples, and Use Cases!**
## π Installation
To install the package, run:
```sh
npm i @lilbunnyrabbit/task-manager
```## π― Features
- **Task Orchestration** β Manage workflows with **sequential** or **parallel** execution.
- **Progress Tracking** β Monitor task progress with built-in state handling.
- **Type Safety** β Built with TypeScript for safe task handling.
- **Composable Workflows** β Reuse task groups for structured execution.
- **Error Recovery** β Handle failures and continue execution.
- **Query Interface** β Access task results, states, and logs.For more details, visit the **[API Documentation](https://lilbunnyrabbit.github.io/task-manager/docs/api/v1.0.0/index.html)**.
## π₯ Getting Started
This system revolves around three core components: **[`Task`](#task)**, **[`TaskGroup`](#taskgroup)**, and **[`TaskManager`](#taskmanager)**.
- **[`Task`](#task)**: Represents a single unit of work with its own logic, data, execution state, and error handling.
- **[`TaskGroup`](#taskgroup)**: Allows grouping related tasks together, managing dependencies, and structuring workflows.
- **[`TaskManager`](#taskmanager)**: Orchestrates execution, handles progress tracking, and manages error recovery.### Creating a Task
Define a task using `createTask`:```ts
import { createTask } from "@lilbunnyrabbit/task-manager";const myTask = createTask({
name: "Example Task",
async execute(id) {
return `Task #${id} Completed!`;
},
});
```### Grouping Tasks with TaskGroup
A `TaskGroup` allows structuring workflows by managing multiple tasks:```ts
import { createTaskGroup } from "@lilbunnyrabbit/task-manager";const exampleGroup = createTaskGroup({
name: "Example Group",
tasks(ids: number[]) {
return ids.map((id) => myTask(id));
},
});
```### Managing Execution with TaskManager
A `TaskManager` runs and tracks task execution:```ts
import { TaskManager } from "@lilbunnyrabbit/task-manager";const manager = new TaskManager();
manager.addTasks(exampleGroup([1, 2, 3]), myTask(4));
manager.start();
```For **more examples**, visit the [Examples Section](https://lilbunnyrabbit.github.io/task-manager/#/examples).
## π Use Cases
Some practical use cases of `@lilbunnyrabbit/task-manager` include:
- **[File Upload Workflow](https://lilbunnyrabbit.github.io/task-manager/#/examples?example=real-life-file-upload)** β Upload files in chunks and track progress.
- **[CI/CD Pipelines](https://lilbunnyrabbit.github.io/task-manager/#/examples?example=real-life-ci-cd-pipeline)** β Automate build, test, and deploy tasks.
- **[Image Processing](https://lilbunnyrabbit.github.io/task-manager/#/examples?example=real-life-image-processing)** β Process images with transformations.
- **[API Request Handling](https://lilbunnyrabbit.github.io/task-manager/#/examples?example=real-life-api-request)** β Fetch and process multiple API responses.See more in the [Use Cases Section](https://lilbunnyrabbit.github.io/task-manager/#/?section=section-use-cases).
## π API Overview
This section provides a rough TypeScript definition of the main components.
### Task
A `Task` represents a unit of work with execution logic, progress tracking, and result management.```ts
interface Task extends TaskBase {
readonly id: string;
readonly name: string;
readonly data: TSpec["TData"]
readonly builder: TaskBuilder
readonly logs: LogEntry[];
readonly query?: TaskQuery;execute(): Promise>;
parse(): ParsedTask;
toString(pretty?: boolean): string;
clone(): Task;
}
```### TaskGroup
A `TaskGroup` manages multiple tasks and defines execution order.```ts
interface TaskGroup extends TaskGroupBase {
readonly id: string;
readonly name: string;
readonly args: TArgs;
readonly builder: TaskGroupBuilder;
readonly mode: ExecutionMode;
readonly tasks: ExecutableTask[];
readonly query: TaskQuery;execute(): Promise;
toString(pretty?: boolean): string;
clone(): TaskGroup;
}
```### TaskManager
A `TaskManager` executes tasks, tracks progress, and manages execution settings.```ts
interface TaskManager extends TaskManagerBase {
readonly tasks: ExecutableTask[];
readonly query: TaskQuery;addTask(task: ExecutableTask): this;
addTasks(...tasks: ExecutableTask[]): this;
start(force?: boolean): Promise;
stop(): void;
reset(): void;
clearQueue(): this;
}
```For **full API documentation**, visit the [Docs](https://lilbunnyrabbit.github.io/task-manager/docs/api/v1.0.0/index.html).
## π§ Development
### Setup
Clone the repository and install dependencies:```sh
git clone https://github.com/lilBunnyRabbit/task-manager.git
cd task-manager
npm install
```### Available Scripts
| Command | Description |
| ----------------------- | ----------------------------------------------------------------------------------------------------- |
| `npm run build` | Compiles [TypeScript](https://www.typescriptlang.org/) code. |
| `npm test` | Runs tests with [Jest](https://jestjs.io/). |
| `npm run clean` | Clears `dist/` and `node_modules/`. |
| `npm run changeset` | Manages versioning and changelog updates with [Changesets](https://github.com/changesets/changesets). |
| `npm run release` | Publishes the package to npm. |
| `npm run generate:docs` | Generates API documentation. |## π¦ Related Packages
These utilities complement `@lilbunnyrabbit/task-manager`:
| Package | Description |
| ------------------------------------------------------------------------------------------------ | -------------------------------------------------- |
| **[@lilbunnyrabbit/event-emitter](https://www.npmjs.com/package/@lilbunnyrabbit/event-emitter)** | A lightweight event system for tasks. |
| **[@lilbunnyrabbit/optional](https://www.npmjs.com/package/@lilbunnyrabbit/optional)** | A TypeScript utility for handling optional values. |
| **[@lilbunnyrabbit/utils](https://www.npmjs.com/package/@lilbunnyrabbit/utils)** | Collection of helper functions and utilities. |## π Contribution
Contributions are always welcome! For any enhancements or bug fixes, please open a pull request linked to the relevant issue. If there's no existing issue related to your contribution, feel free to create one.
## π Support
Your support is greatly appreciated! If this package has been helpful, consider supporting its development. Your contributions help maintain and improve this project.
[](https://github.com/sponsors/lilBunnyRabbit)
## π License
MIT Β© AndraΕΎ MesariΔ-Sirec