You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+19-6Lines changed: 19 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,20 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
5
5
## Project Overview
6
6
7
-
This is `@muniter/queue`, a TypeScript queue system inspired by Yii2-Queue architecture. It provides a clean abstraction for job processing with multiple storage backends (Database and Amazon SQS).
7
+
This is `@muniter/queue`, a TypeScript queue system inspired by Yii2-Queue architecture. It provides a clean abstraction for job processing with multiple storage backends (Database, Amazon SQS, and File system).
8
+
9
+
### What This Package Does
10
+
11
+
**@muniter/queue** is an event-driven job queue system that allows you to:
12
+
- Define job types as TypeScript interfaces (not classes) for type safety
13
+
- Register job handlers using simple `onJob()` callbacks
14
+
- Add jobs to queues with compile-time validation of payloads and options
15
+
- Process jobs asynchronously with configurable workers
16
+
- Switch between storage backends (File, Database, SQS) without changing job code
17
+
- Monitor job lifecycle through built-in events
18
+
- Run jobs in isolated processes for improved stability
19
+
20
+
Key differentiator: Unlike traditional job queue systems that require job classes, this uses an event-based approach where you define job types as interfaces and register handlers as functions, making it simpler and more TypeScript-friendly.
8
21
9
22
## Essential Commands
10
23
@@ -35,15 +48,15 @@ The CLI worker supports these arguments:
35
48
-**DbQueue** (`src/drivers/db.ts`): Database-backed queue using DatabaseAdapter interface
-**FileQueue** (`src/drivers/file.ts`): File-based queue storing jobs as individual files with JSON index
38
-
3.**Jobs**: Units of work implementing the `Job<T>` interface with `execute(queue: Queue)` method
51
+
3.**Jobs**: Defined as TypeScript interfaces in a JobMap, with handlers registered via `onJob()` method
39
52
4.**Workers**: Long-running processes that consume and execute jobs
40
53
5.**Serialization**: Pluggable serialization system for job payloads
41
54
42
55
### Key Interfaces
43
56
44
-
-**Job**: Core interface for all jobs with `execute(queue: Queue): Promise<T> | T`
57
+
-**JobMap**: TypeScript interface mapping job names to their payload types (e.g., `{ 'send-email': { to: string; subject: string } }`)
45
58
-**DatabaseAdapter**: Interface that database implementations must satisfy
46
-
-**QueueMessage**: Internal message format with id, payload (Buffer), and metadata
59
+
-**QueueMessage**: Internal message format with id, payload (string), and metadata
47
60
-**JobMeta**: Metadata for jobs including TTR, delay, priority, timestamps
48
61
49
62
### Driver Architecture
@@ -63,7 +76,7 @@ The queue emits lifecycle events:
63
76
## Development Patterns
64
77
65
78
### Job Implementation
66
-
Jobs implement the `Job<T>` interface. The payload is serialized using the configured serializer (defaults to JSON).
79
+
Jobs are defined as TypeScript interfaces in a JobMap type, and handlers are registered using the `onJob()` method. The payload is serialized using JSON by default.
67
80
68
81
### Database Adapters
69
82
When implementing DatabaseAdapter, you must provide:
@@ -87,7 +100,7 @@ The `example-queue-project/` directory contains a working example with SQLite da
87
100
## Important Notes
88
101
89
102
- The CLI worker is a template - it requires user-provided database adapters or SQS clients
90
-
- Jobs are serialized as Buffer objects and must be deserializable
103
+
- Jobs are serialized as JSON strings (job name + payload) and stored as Buffers in database adapters
91
104
- TTR (Time To Run) defaults to 300 seconds but can be configured per job
92
105
- SQS driver uses message attributes for metadata and base64 encoding for payloads
93
106
- The queue system is designed to be backend-agnostic through the driver pattern
0 commit comments