Skip to content

Commit 9e98319

Browse files
committed
docs: ✏️ Added readme file for the queue package
1 parent 64f2e43 commit 9e98319

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

packages/queue/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# @windingtree/sdk-queue
2+
3+
This package provides a task queue system designed to manage jobs that need to be executed in an asynchronous, distributed manner.
4+
5+
## Installation
6+
7+
```bash
8+
pnpm i @windingtree/sdk-queue
9+
```
10+
11+
## Key concepts
12+
13+
This library introduces several classes:
14+
15+
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`.
16+
17+
2. `JobHandler`: This is a function that a job runs when it's its turn to be executed by the queue.
18+
19+
3. `JobHandlerRegistry`: This class manages job handlers. It allows for registering and retrieving handlers by name.
20+
21+
4. `Queue`: This is the main class of this package. It's responsible for managing and executing jobs.
22+
23+
5. `JobStatus`: An enum representing the different states a job can be in.
24+
25+
## Usage
26+
27+
```typescript
28+
import { Queue, JobConfig } from '@windingtree/sdk-queue';
29+
30+
// Create a new queue
31+
const queue = new Queue({ concurrencyLimit: 5 });
32+
33+
// Register a job handler
34+
queue.registerHandler('myHandler', async (data) => {
35+
// Process data here
36+
console.log(data);
37+
return true;
38+
});
39+
40+
// Create a job config
41+
const jobConfig: JobConfig = {
42+
handlerName: 'myHandler',
43+
data: { key: 'value' },
44+
maxRetries: 3,
45+
};
46+
47+
// Add a job to the queue
48+
const jobId = queue.add(jobConfig);
49+
50+
// You can also get a job
51+
const job = queue.get(jobId);
52+
53+
// Or cancel a job
54+
queue.cancel(jobId);
55+
56+
// Or delete a job
57+
queue.delete(jobId);
58+
```
59+
60+
## Documentation
61+
62+
For full documentation and examples, visit [windingtree.github.io/sdk](https://windingtree.github.io/sdk)
63+
64+
## Testing
65+
66+
```bash
67+
pnpm test
68+
```
69+
70+
## Contributing
71+
72+
[Contribution guidelines](https://windingtree.github.io/sdk/#/docs/contribution)

0 commit comments

Comments
 (0)