Skip to content

Commit 8eaaf0a

Browse files
committed
improve claude docs
1 parent b03beab commit 8eaaf0a

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

CLAUDE.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

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.
821

922
## Essential Commands
1023

@@ -35,15 +48,15 @@ The CLI worker supports these arguments:
3548
- **DbQueue** (`src/drivers/db.ts`): Database-backed queue using DatabaseAdapter interface
3649
- **SqsQueue** (`src/drivers/sqs.ts`): Amazon SQS-backed queue
3750
- **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
3952
4. **Workers**: Long-running processes that consume and execute jobs
4053
5. **Serialization**: Pluggable serialization system for job payloads
4154

4255
### Key Interfaces
4356

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 } }`)
4558
- **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
4760
- **JobMeta**: Metadata for jobs including TTR, delay, priority, timestamps
4861

4962
### Driver Architecture
@@ -63,7 +76,7 @@ The queue emits lifecycle events:
6376
## Development Patterns
6477

6578
### 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.
6780

6881
### Database Adapters
6982
When implementing DatabaseAdapter, you must provide:
@@ -87,7 +100,7 @@ The `example-queue-project/` directory contains a working example with SQLite da
87100
## Important Notes
88101

89102
- 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
91104
- TTR (Time To Run) defaults to 300 seconds but can be configured per job
92105
- SQS driver uses message attributes for metadata and base64 encoding for payloads
93106
- The queue system is designed to be backend-agnostic through the driver pattern

0 commit comments

Comments
 (0)