@cinnabun/queue 0.0.1 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @cinnabun/queue
|
|
2
|
+
|
|
3
|
+
Job queue module for Cinnabun. Background jobs with Redis or in-memory adapters.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @cinnabun/queue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### 1. Configure the module
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { CinnabunApp, CinnabunFactory } from "@cinnabun/core";
|
|
17
|
+
import { QueueModule, QueuePlugin, MemoryAdapter } from "@cinnabun/queue";
|
|
18
|
+
|
|
19
|
+
@CinnabunApp({
|
|
20
|
+
port: 3000,
|
|
21
|
+
scanPaths: [],
|
|
22
|
+
imports: [
|
|
23
|
+
QueueModule.forRoot({
|
|
24
|
+
adapter: MemoryAdapter,
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
plugins: [new QueuePlugin()],
|
|
28
|
+
})
|
|
29
|
+
class App {}
|
|
30
|
+
|
|
31
|
+
CinnabunFactory.run(App);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 2. Define jobs and processors
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Processor, Job } from "@cinnabun/queue";
|
|
38
|
+
|
|
39
|
+
@Processor("email")
|
|
40
|
+
class EmailProcessor {
|
|
41
|
+
@Job("welcome")
|
|
42
|
+
async sendWelcome(data: { userId: string; email: string }) {
|
|
43
|
+
// Send welcome email
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Enqueue jobs
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { QueueService } from "@cinnabun/queue";
|
|
52
|
+
|
|
53
|
+
@RestController("/api")
|
|
54
|
+
class UserController {
|
|
55
|
+
constructor(private queue: QueueService) {}
|
|
56
|
+
|
|
57
|
+
@PostMapping("/users")
|
|
58
|
+
async create(@Body() body: CreateUserDto) {
|
|
59
|
+
const user = await this.userService.create(body);
|
|
60
|
+
await this.queue.add("email", "welcome", { userId: user.id, email: user.email });
|
|
61
|
+
return user;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 4. Run the worker
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bun run cinnabun worker
|
|
70
|
+
# or
|
|
71
|
+
bun run node_modules/@cinnabun/queue/dist/worker-bootstrap.js
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Adapters
|
|
75
|
+
|
|
76
|
+
- **MemoryAdapter** — In-memory (development)
|
|
77
|
+
- **RedisAdapter** — Redis-backed (production)
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|