@gravito/stream 1.0.0-alpha.2
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 +319 -0
- package/dist/Consumer.d.ts +67 -0
- package/dist/Consumer.d.ts.map +1 -0
- package/dist/Job.d.ts +76 -0
- package/dist/Job.d.ts.map +1 -0
- package/dist/OrbitQueue.d.ts +74 -0
- package/dist/OrbitQueue.d.ts.map +1 -0
- package/dist/QueueManager.d.ts +86 -0
- package/dist/QueueManager.d.ts.map +1 -0
- package/dist/Queueable.d.ts +63 -0
- package/dist/Queueable.d.ts.map +1 -0
- package/dist/Worker.d.ts +48 -0
- package/dist/Worker.d.ts.map +1 -0
- package/dist/core/src/ConfigManager.d.ts +26 -0
- package/dist/core/src/ConfigManager.d.ts.map +1 -0
- package/dist/core/src/Container.d.ts +39 -0
- package/dist/core/src/Container.d.ts.map +1 -0
- package/dist/core/src/Event.d.ts +6 -0
- package/dist/core/src/Event.d.ts.map +1 -0
- package/dist/core/src/EventManager.d.ts +124 -0
- package/dist/core/src/EventManager.d.ts.map +1 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts +32 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts.map +1 -0
- package/dist/core/src/HookManager.d.ts +29 -0
- package/dist/core/src/HookManager.d.ts.map +1 -0
- package/dist/core/src/Listener.d.ts +5 -0
- package/dist/core/src/Listener.d.ts.map +1 -0
- package/dist/core/src/Logger.d.ts +21 -0
- package/dist/core/src/Logger.d.ts.map +1 -0
- package/dist/core/src/PlanetCore.d.ts +116 -0
- package/dist/core/src/PlanetCore.d.ts.map +1 -0
- package/dist/core/src/Route.d.ts +13 -0
- package/dist/core/src/Route.d.ts.map +1 -0
- package/dist/core/src/Router.d.ts +168 -0
- package/dist/core/src/Router.d.ts.map +1 -0
- package/dist/core/src/ServiceProvider.d.ts +17 -0
- package/dist/core/src/ServiceProvider.d.ts.map +1 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts +5 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts.map +1 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts +5 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts.map +1 -0
- package/dist/core/src/exceptions/GravitoException.d.ts +15 -0
- package/dist/core/src/exceptions/GravitoException.d.ts.map +1 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +7 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts.map +1 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +15 -0
- package/dist/core/src/exceptions/ValidationException.d.ts.map +1 -0
- package/dist/core/src/exceptions/index.d.ts +6 -0
- package/dist/core/src/exceptions/index.d.ts.map +1 -0
- package/dist/core/src/helpers/Arr.d.ts +15 -0
- package/dist/core/src/helpers/Arr.d.ts.map +1 -0
- package/dist/core/src/helpers/Str.d.ts +19 -0
- package/dist/core/src/helpers/Str.d.ts.map +1 -0
- package/dist/core/src/helpers/data.d.ts +6 -0
- package/dist/core/src/helpers/data.d.ts.map +1 -0
- package/dist/core/src/helpers/errors.d.ts +13 -0
- package/dist/core/src/helpers/errors.d.ts.map +1 -0
- package/dist/core/src/helpers/response.d.ts +19 -0
- package/dist/core/src/helpers/response.d.ts.map +1 -0
- package/dist/core/src/helpers.d.ts +39 -0
- package/dist/core/src/helpers.d.ts.map +1 -0
- package/dist/core/src/http/CookieJar.d.ts +34 -0
- package/dist/core/src/http/CookieJar.d.ts.map +1 -0
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +13 -0
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts.map +1 -0
- package/dist/core/src/index.d.ts +32 -0
- package/dist/core/src/index.d.ts.map +1 -0
- package/dist/core/src/security/Encrypter.d.ts +25 -0
- package/dist/core/src/security/Encrypter.d.ts.map +1 -0
- package/dist/core/src/security/Hasher.d.ts +30 -0
- package/dist/core/src/security/Hasher.d.ts.map +1 -0
- package/dist/core/src/types/events.d.ts +95 -0
- package/dist/core/src/types/events.d.ts.map +1 -0
- package/dist/drivers/DatabaseDriver.d.ts +60 -0
- package/dist/drivers/DatabaseDriver.d.ts.map +1 -0
- package/dist/drivers/KafkaDriver.d.ts +134 -0
- package/dist/drivers/KafkaDriver.d.ts.map +1 -0
- package/dist/drivers/MemoryDriver.d.ts +45 -0
- package/dist/drivers/MemoryDriver.d.ts.map +1 -0
- package/dist/drivers/QueueDriver.d.ts +89 -0
- package/dist/drivers/QueueDriver.d.ts.map +1 -0
- package/dist/drivers/RedisDriver.d.ts +79 -0
- package/dist/drivers/RedisDriver.d.ts.map +1 -0
- package/dist/drivers/SQSDriver.d.ts +100 -0
- package/dist/drivers/SQSDriver.d.ts.map +1 -0
- package/dist/index.cjs +32101 -0
- package/dist/index.cjs.map +422 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +32095 -0
- package/dist/index.mjs.map +422 -0
- package/dist/orbit-db/src/DBService.d.ts +270 -0
- package/dist/orbit-db/src/DBService.d.ts.map +1 -0
- package/dist/orbit-db/src/EventBus.d.ts +53 -0
- package/dist/orbit-db/src/EventBus.d.ts.map +1 -0
- package/dist/orbit-db/src/MigrationDriver.d.ts +55 -0
- package/dist/orbit-db/src/MigrationDriver.d.ts.map +1 -0
- package/dist/orbit-db/src/Model.d.ts +564 -0
- package/dist/orbit-db/src/Model.d.ts.map +1 -0
- package/dist/orbit-db/src/ModelCollection.d.ts +35 -0
- package/dist/orbit-db/src/ModelCollection.d.ts.map +1 -0
- package/dist/orbit-db/src/index.d.ts +34 -0
- package/dist/orbit-db/src/index.d.ts.map +1 -0
- package/dist/orbit-db/src/types.d.ts +146 -0
- package/dist/orbit-db/src/types.d.ts.map +1 -0
- package/dist/orbit-queue/src/Consumer.d.ts +67 -0
- package/dist/orbit-queue/src/Consumer.d.ts.map +1 -0
- package/dist/orbit-queue/src/Job.d.ts +76 -0
- package/dist/orbit-queue/src/Job.d.ts.map +1 -0
- package/dist/orbit-queue/src/OrbitQueue.d.ts +74 -0
- package/dist/orbit-queue/src/OrbitQueue.d.ts.map +1 -0
- package/dist/orbit-queue/src/QueueManager.d.ts +86 -0
- package/dist/orbit-queue/src/QueueManager.d.ts.map +1 -0
- package/dist/orbit-queue/src/Queueable.d.ts +63 -0
- package/dist/orbit-queue/src/Queueable.d.ts.map +1 -0
- package/dist/orbit-queue/src/Worker.d.ts +48 -0
- package/dist/orbit-queue/src/Worker.d.ts.map +1 -0
- package/dist/orbit-queue/src/drivers/DatabaseDriver.d.ts +60 -0
- package/dist/orbit-queue/src/drivers/DatabaseDriver.d.ts.map +1 -0
- package/dist/orbit-queue/src/drivers/KafkaDriver.d.ts +134 -0
- package/dist/orbit-queue/src/drivers/KafkaDriver.d.ts.map +1 -0
- package/dist/orbit-queue/src/drivers/MemoryDriver.d.ts +45 -0
- package/dist/orbit-queue/src/drivers/MemoryDriver.d.ts.map +1 -0
- package/dist/orbit-queue/src/drivers/QueueDriver.d.ts +89 -0
- package/dist/orbit-queue/src/drivers/QueueDriver.d.ts.map +1 -0
- package/dist/orbit-queue/src/drivers/RedisDriver.d.ts +79 -0
- package/dist/orbit-queue/src/drivers/RedisDriver.d.ts.map +1 -0
- package/dist/orbit-queue/src/drivers/SQSDriver.d.ts +100 -0
- package/dist/orbit-queue/src/drivers/SQSDriver.d.ts.map +1 -0
- package/dist/orbit-queue/src/index.d.ts +45 -0
- package/dist/orbit-queue/src/index.d.ts.map +1 -0
- package/dist/orbit-queue/src/serializers/ClassNameSerializer.d.ts +46 -0
- package/dist/orbit-queue/src/serializers/ClassNameSerializer.d.ts.map +1 -0
- package/dist/orbit-queue/src/serializers/JobSerializer.d.ts +36 -0
- package/dist/orbit-queue/src/serializers/JobSerializer.d.ts.map +1 -0
- package/dist/orbit-queue/src/serializers/JsonSerializer.d.ts +32 -0
- package/dist/orbit-queue/src/serializers/JsonSerializer.d.ts.map +1 -0
- package/dist/orbit-queue/src/types.d.ts +85 -0
- package/dist/orbit-queue/src/types.d.ts.map +1 -0
- package/dist/serializers/ClassNameSerializer.d.ts +46 -0
- package/dist/serializers/ClassNameSerializer.d.ts.map +1 -0
- package/dist/serializers/JobSerializer.d.ts +36 -0
- package/dist/serializers/JobSerializer.d.ts.map +1 -0
- package/dist/serializers/JsonSerializer.d.ts +32 -0
- package/dist/serializers/JsonSerializer.d.ts.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# @gravito/stream
|
|
2
|
+
|
|
3
|
+
輕量、高效的隊列系統,借鑑 Laravel 架構但保持 Gravito 的核心價值(高效能、低耗、輕量、AI 友善)。支援多種儲存驅動、內嵌與獨立 Consumer 模式,以及多種 Job 序列化方式。
|
|
4
|
+
|
|
5
|
+
> **狀態**:v0.1.0 - 核心功能已完成,支援 Memory、Database、Redis、Kafka、SQS 驅動
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- **零運行時開銷**:純型別包裝,直接委派給驅動
|
|
10
|
+
- **多驅動支援**:Memory、Database、Redis、Kafka、SQS 等
|
|
11
|
+
- **完全模組化**:按需安裝驅動,核心包極小(< 50KB)
|
|
12
|
+
- **內嵌與獨立模式**:開發時內嵌運行,生產環境可獨立部署
|
|
13
|
+
- **AI 友善**:完整的型別推導、清晰的 JSDoc、直觀的 API
|
|
14
|
+
|
|
15
|
+
## 安裝
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @gravito/stream
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 快速開始
|
|
22
|
+
|
|
23
|
+
### 1. 建立 Job
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { Job } from '@gravito/stream'
|
|
27
|
+
|
|
28
|
+
export class SendWelcomeEmail extends Job {
|
|
29
|
+
constructor(private userId: string) {
|
|
30
|
+
super()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async handle(): Promise<void> {
|
|
34
|
+
// 處理邏輯
|
|
35
|
+
const user = await User.find(this.userId)
|
|
36
|
+
await mail.send(new WelcomeEmail(user))
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. 推送 Job
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// 在 Controller 中
|
|
45
|
+
const queue = c.get('queue')
|
|
46
|
+
|
|
47
|
+
await queue.push(new SendWelcomeEmail(user.id))
|
|
48
|
+
.onQueue('emails')
|
|
49
|
+
.delay(60) // 延遲 60 秒
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. 配置 OrbitStream
|
|
53
|
+
|
|
54
|
+
#### 使用 Memory Driver(開發用)
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { OrbitStream } from '@gravito/stream'
|
|
58
|
+
|
|
59
|
+
const core = await PlanetCore.boot({
|
|
60
|
+
orbits: [
|
|
61
|
+
OrbitStream.configure({
|
|
62
|
+
default: 'memory',
|
|
63
|
+
connections: {
|
|
64
|
+
memory: { driver: 'memory' }
|
|
65
|
+
},
|
|
66
|
+
autoStartWorker: true,
|
|
67
|
+
workerOptions: {
|
|
68
|
+
queues: ['default', 'emails']
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### 使用 Database Driver
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { OrbitStream } from '@gravito/stream'
|
|
79
|
+
import { OrbitDB } from '@gravito/db'
|
|
80
|
+
|
|
81
|
+
const core = await PlanetCore.boot({
|
|
82
|
+
orbits: [
|
|
83
|
+
OrbitDB.configure({ db: drizzleClient }),
|
|
84
|
+
OrbitStream.configure({
|
|
85
|
+
default: 'database',
|
|
86
|
+
connections: {
|
|
87
|
+
database: {
|
|
88
|
+
driver: 'database',
|
|
89
|
+
table: 'jobs' // 可選,預設為 'jobs'
|
|
90
|
+
// dbService 會自動從 Context 取得(如果 OrbitDB 已安裝)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
]
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### 使用 Redis Driver
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { OrbitStream } from '@gravito/stream'
|
|
102
|
+
import Redis from 'ioredis'
|
|
103
|
+
|
|
104
|
+
const redis = new Redis('redis://localhost:6379')
|
|
105
|
+
|
|
106
|
+
const core = await PlanetCore.boot({
|
|
107
|
+
orbits: [
|
|
108
|
+
OrbitStream.configure({
|
|
109
|
+
default: 'redis',
|
|
110
|
+
connections: {
|
|
111
|
+
redis: {
|
|
112
|
+
driver: 'redis',
|
|
113
|
+
client: redis,
|
|
114
|
+
prefix: 'queue:' // 可選
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
]
|
|
119
|
+
})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### 使用 Kafka Driver
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { OrbitStream } from '@gravito/stream'
|
|
126
|
+
import { Kafka } from 'kafkajs'
|
|
127
|
+
|
|
128
|
+
const kafka = new Kafka({
|
|
129
|
+
brokers: ['localhost:9092'],
|
|
130
|
+
clientId: 'gravito-app'
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const core = await PlanetCore.boot({
|
|
134
|
+
orbits: [
|
|
135
|
+
OrbitStream.configure({
|
|
136
|
+
default: 'kafka',
|
|
137
|
+
connections: {
|
|
138
|
+
kafka: {
|
|
139
|
+
driver: 'kafka',
|
|
140
|
+
client: kafka,
|
|
141
|
+
consumerGroupId: 'gravito-workers'
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
]
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### 使用 SQS Driver
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { OrbitStream } from '@gravito/stream'
|
|
153
|
+
import { SQSClient } from '@aws-sdk/client-sqs'
|
|
154
|
+
|
|
155
|
+
const sqs = new SQSClient({
|
|
156
|
+
region: 'us-east-1',
|
|
157
|
+
credentials: {
|
|
158
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
159
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const core = await PlanetCore.boot({
|
|
164
|
+
orbits: [
|
|
165
|
+
OrbitStream.configure({
|
|
166
|
+
default: 'sqs',
|
|
167
|
+
connections: {
|
|
168
|
+
sqs: {
|
|
169
|
+
driver: 'sqs',
|
|
170
|
+
client: sqs,
|
|
171
|
+
queueUrlPrefix: 'https://sqs.us-east-1.amazonaws.com/123456789012', // 可選
|
|
172
|
+
visibilityTimeout: 30, // 可選
|
|
173
|
+
waitTimeSeconds: 20 // 可選,長輪詢
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
]
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## 資料庫 Schema
|
|
182
|
+
|
|
183
|
+
如果使用 Database Driver,需要建立以下資料表:
|
|
184
|
+
|
|
185
|
+
```sql
|
|
186
|
+
CREATE TABLE jobs (
|
|
187
|
+
id BIGSERIAL PRIMARY KEY,
|
|
188
|
+
queue VARCHAR(255) NOT NULL,
|
|
189
|
+
payload TEXT NOT NULL,
|
|
190
|
+
attempts INT DEFAULT 0,
|
|
191
|
+
reserved_at TIMESTAMP,
|
|
192
|
+
available_at TIMESTAMP NOT NULL,
|
|
193
|
+
created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
CREATE INDEX idx_jobs_queue_available ON jobs(queue, available_at);
|
|
197
|
+
CREATE INDEX idx_jobs_reserved ON jobs(reserved_at);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## 獨立 Consumer(微服務模式)
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
# 使用 Database
|
|
204
|
+
bun run packages/orbit-queue/cli/queue-worker.ts \
|
|
205
|
+
--connection=database \
|
|
206
|
+
--queues=default,emails \
|
|
207
|
+
--workers=4
|
|
208
|
+
|
|
209
|
+
# 使用 Kafka
|
|
210
|
+
bun run packages/orbit-queue/cli/queue-worker.ts \
|
|
211
|
+
--connection=kafka \
|
|
212
|
+
--queues=default,emails \
|
|
213
|
+
--consumer-group=gravito-workers
|
|
214
|
+
|
|
215
|
+
# 使用 SQS
|
|
216
|
+
bun run packages/orbit-queue/cli/queue-worker.ts \
|
|
217
|
+
--connection=sqs \
|
|
218
|
+
--queues=default,emails \
|
|
219
|
+
--region=us-east-1
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## API 參考
|
|
223
|
+
|
|
224
|
+
### Job
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
abstract class Job implements Queueable {
|
|
228
|
+
abstract handle(): Promise<void>
|
|
229
|
+
async failed(error: Error): Promise<void>
|
|
230
|
+
|
|
231
|
+
onQueue(queue: string): this
|
|
232
|
+
onConnection(connection: string): this
|
|
233
|
+
delay(seconds: number): this
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### QueueManager
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
class QueueManager {
|
|
241
|
+
async push<T extends Job>(job: T): Promise<T>
|
|
242
|
+
async pushMany<T extends Job>(jobs: T[]): Promise<void>
|
|
243
|
+
async pop(queue?: string, connection?: string): Promise<Job | null>
|
|
244
|
+
async size(queue?: string, connection?: string): Promise<number>
|
|
245
|
+
async clear(queue?: string, connection?: string): Promise<void>
|
|
246
|
+
registerJobClasses(jobClasses: Array<new (...args: unknown[]) => Job>): void
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## 設計原則
|
|
251
|
+
|
|
252
|
+
- **高效能**:零運行時開銷,直接委派給驅動,支援批量操作
|
|
253
|
+
- **低耗**:最小化依賴,重用現有連接(DatabaseDriver 重用 orbit-db)
|
|
254
|
+
- **輕量**:核心包極小(< 50KB),驅動完全模組化,按需載入
|
|
255
|
+
- **AI 友善**:完整的型別推導,清晰的 JSDoc,直觀的 API
|
|
256
|
+
|
|
257
|
+
## 已實作的驅動
|
|
258
|
+
|
|
259
|
+
### 基礎驅動
|
|
260
|
+
|
|
261
|
+
- ✅ **MemoryDriver** - 記憶體驅動(開發用,零配置)
|
|
262
|
+
- ✅ **DatabaseDriver** - 資料庫驅動(PostgreSQL、MySQL、SQLite)
|
|
263
|
+
- ✅ **RedisDriver** - Redis 驅動(支援延遲執行)
|
|
264
|
+
|
|
265
|
+
### 企業級 Broker 驅動
|
|
266
|
+
|
|
267
|
+
- ✅ **KafkaDriver** - Apache Kafka 驅動(支援 Topic、Consumer Groups)
|
|
268
|
+
- ✅ **SQSDriver** - AWS SQS 驅動(支援標準/FIFO 隊列、長輪詢)
|
|
269
|
+
|
|
270
|
+
## 未來規劃
|
|
271
|
+
|
|
272
|
+
以下 broker 驅動計劃在後續版本中實作:
|
|
273
|
+
|
|
274
|
+
### 計劃中的驅動
|
|
275
|
+
|
|
276
|
+
- 🔜 **RabbitMQDriver** - RabbitMQ 驅動
|
|
277
|
+
- 支援 Exchange 和 Queue 管理
|
|
278
|
+
- 支援多種 Exchange 類型(direct、topic、fanout、headers)
|
|
279
|
+
- 支援持久化隊列
|
|
280
|
+
- 支援確認機制
|
|
281
|
+
|
|
282
|
+
- 🔜 **NATSDriver** - NATS 驅動
|
|
283
|
+
- 支援 JetStream(持久化消息)
|
|
284
|
+
- 支援訂閱模式
|
|
285
|
+
- 支援請求/回應模式
|
|
286
|
+
|
|
287
|
+
- 🔜 **GooglePubSubDriver** - Google Cloud Pub/Sub 驅動
|
|
288
|
+
- 支援 Topic 和 Subscription 管理
|
|
289
|
+
- 支援批量操作
|
|
290
|
+
- 支援死信主題(Dead Letter Topic)
|
|
291
|
+
|
|
292
|
+
- 🔜 **AzureServiceBusDriver** - Azure Service Bus 驅動
|
|
293
|
+
- 支援 Queue 和 Topic 管理
|
|
294
|
+
- 支援會話(Sessions)
|
|
295
|
+
- 支援死信隊列
|
|
296
|
+
|
|
297
|
+
- 🔜 **BeanstalkdDriver** - Beanstalkd 驅動
|
|
298
|
+
- 輕量級消息隊列
|
|
299
|
+
- 支援優先級和延遲
|
|
300
|
+
- 支援 TTR(Time To Run)
|
|
301
|
+
|
|
302
|
+
### 貢獻指南
|
|
303
|
+
|
|
304
|
+
如果您想為 Gravito Queue 添加新的 broker 驅動,請:
|
|
305
|
+
|
|
306
|
+
1. 實作 `QueueDriver` 介面
|
|
307
|
+
2. 確保符合核心原則(高效能、低耗、輕量、AI 友善)
|
|
308
|
+
3. 添加完整的 JSDoc 註解
|
|
309
|
+
4. 添加單元測試
|
|
310
|
+
5. 更新 README 文件
|
|
311
|
+
|
|
312
|
+
## 相關文件
|
|
313
|
+
|
|
314
|
+
- [ROADMAP.md](./ROADMAP.md) - 詳細的路線圖和計劃
|
|
315
|
+
- [MIGRATION.md](./MIGRATION.md) - 資料庫遷移腳本
|
|
316
|
+
|
|
317
|
+
## 授權
|
|
318
|
+
|
|
319
|
+
MIT
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { QueueManager } from './QueueManager';
|
|
2
|
+
import type { WorkerOptions } from './Worker';
|
|
3
|
+
/**
|
|
4
|
+
* Consumer options.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConsumerOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Queues to listen on.
|
|
9
|
+
*/
|
|
10
|
+
queues: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Connection name.
|
|
13
|
+
*/
|
|
14
|
+
connection?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Worker options.
|
|
17
|
+
*/
|
|
18
|
+
workerOptions?: WorkerOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Polling interval (milliseconds).
|
|
21
|
+
*/
|
|
22
|
+
pollInterval?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to keep polling when queues are empty.
|
|
25
|
+
*/
|
|
26
|
+
keepAlive?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Consumer
|
|
30
|
+
*
|
|
31
|
+
* Consumes and executes jobs from queues.
|
|
32
|
+
* Supports embedded mode (inside the main app) and standalone mode (as a worker service).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Embedded mode
|
|
37
|
+
* const consumer = new Consumer(queueManager, {
|
|
38
|
+
* queues: ['default', 'emails'],
|
|
39
|
+
* pollInterval: 1000
|
|
40
|
+
* })
|
|
41
|
+
*
|
|
42
|
+
* consumer.start()
|
|
43
|
+
*
|
|
44
|
+
* // Standalone mode (CLI)
|
|
45
|
+
* // Start via CLI tooling with graceful shutdown
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class Consumer {
|
|
49
|
+
private queueManager;
|
|
50
|
+
private options;
|
|
51
|
+
private running;
|
|
52
|
+
private stopRequested;
|
|
53
|
+
constructor(queueManager: QueueManager, options: ConsumerOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Start the consumer loop.
|
|
56
|
+
*/
|
|
57
|
+
start(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Stop the consumer loop (graceful shutdown).
|
|
60
|
+
*/
|
|
61
|
+
stop(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Check whether the consumer is running.
|
|
64
|
+
*/
|
|
65
|
+
isRunning(): boolean;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=Consumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Consumer.d.ts","sourceRoot":"","sources":["../src/Consumer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAG7C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAA;IAEhB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAE7B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAQ;IAKjB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,OAAO;IALjB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,aAAa,CAAQ;gBAGnB,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,eAAe;IAGlC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAmD5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAU3B;;OAEG;IACH,SAAS,IAAI,OAAO;CAGrB"}
|
package/dist/Job.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Queueable } from './Queueable';
|
|
2
|
+
/**
|
|
3
|
+
* Base Job.
|
|
4
|
+
*
|
|
5
|
+
* All tasks that should be pushed to a queue should extend this class.
|
|
6
|
+
* Implements the `Queueable` interface, providing a fluent API for queue/connection/delay.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* class SendWelcomeEmail extends Job {
|
|
11
|
+
* constructor(private userId: string) {
|
|
12
|
+
* super()
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* async handle(): Promise<void> {
|
|
16
|
+
* const user = await User.find(this.userId)
|
|
17
|
+
* await mail.send(new WelcomeEmail(user))
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // Usage
|
|
22
|
+
* await queue.push(new SendWelcomeEmail('123'))
|
|
23
|
+
* .onQueue('emails')
|
|
24
|
+
* .delay(60)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare abstract class Job implements Queueable {
|
|
28
|
+
/**
|
|
29
|
+
* Queue name.
|
|
30
|
+
*/
|
|
31
|
+
queueName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Connection name.
|
|
34
|
+
*/
|
|
35
|
+
connectionName?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Delay before execution (seconds).
|
|
38
|
+
*/
|
|
39
|
+
delaySeconds?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Current attempt number.
|
|
42
|
+
*/
|
|
43
|
+
attempts?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Maximum attempts.
|
|
46
|
+
*/
|
|
47
|
+
maxAttempts?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Set target queue.
|
|
50
|
+
*/
|
|
51
|
+
onQueue(queue: string): this;
|
|
52
|
+
/**
|
|
53
|
+
* Set target connection.
|
|
54
|
+
*/
|
|
55
|
+
onConnection(connection: string): this;
|
|
56
|
+
/**
|
|
57
|
+
* Set delay (seconds).
|
|
58
|
+
*/
|
|
59
|
+
delay(delay: number): this;
|
|
60
|
+
/**
|
|
61
|
+
* Job handler logic.
|
|
62
|
+
*
|
|
63
|
+
* Subclasses must implement this method.
|
|
64
|
+
*/
|
|
65
|
+
abstract handle(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Failure handler (optional).
|
|
68
|
+
*
|
|
69
|
+
* Called when the job fails and reaches the maximum number of attempts.
|
|
70
|
+
* Subclasses can override to implement custom failure handling.
|
|
71
|
+
*
|
|
72
|
+
* @param error - Error instance
|
|
73
|
+
*/
|
|
74
|
+
failed(_error: Error): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=Job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Job.d.ts","sourceRoot":"","sources":["../src/Job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8BAAsB,GAAI,YAAW,SAAS;IAC5C;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK5B;;OAEG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKtC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK1B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAEhC;;;;;;;OAOG;IACG,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3C"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { GravitoOrbit, PlanetCore } from 'gravito-core';
|
|
2
|
+
import type { ConsumerOptions } from './Consumer';
|
|
3
|
+
import { QueueManager } from './QueueManager';
|
|
4
|
+
import type { QueueConfig } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Orbit Queue configuration options.
|
|
7
|
+
*/
|
|
8
|
+
export interface OrbitQueueOptions extends QueueConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Whether to auto-start an embedded worker in development.
|
|
11
|
+
*/
|
|
12
|
+
autoStartWorker?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Embedded worker options.
|
|
15
|
+
*/
|
|
16
|
+
workerOptions?: ConsumerOptions;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Orbit Queue
|
|
20
|
+
*
|
|
21
|
+
* Gravito Orbit implementation providing queue functionality.
|
|
22
|
+
* Integrates with PlanetCore and injects a `queue` service into the Hono Context.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const core = await PlanetCore.boot({
|
|
27
|
+
* orbits: [
|
|
28
|
+
* OrbitQueue.configure({
|
|
29
|
+
* default: 'database',
|
|
30
|
+
* connections: {
|
|
31
|
+
* database: { driver: 'database', table: 'jobs' }
|
|
32
|
+
* }
|
|
33
|
+
* })
|
|
34
|
+
* ]
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* // Use in a controller/handler
|
|
38
|
+
* const queue = c.get('queue')
|
|
39
|
+
* await queue.push(new SendEmail('user@example.com'))
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class OrbitQueue implements GravitoOrbit {
|
|
43
|
+
private options;
|
|
44
|
+
private queueManager?;
|
|
45
|
+
private consumer?;
|
|
46
|
+
constructor(options?: OrbitQueueOptions);
|
|
47
|
+
/**
|
|
48
|
+
* Static configuration helper.
|
|
49
|
+
*/
|
|
50
|
+
static configure(options: OrbitQueueOptions): OrbitQueue;
|
|
51
|
+
/**
|
|
52
|
+
* Install into PlanetCore.
|
|
53
|
+
*/
|
|
54
|
+
install(core: PlanetCore): void;
|
|
55
|
+
/**
|
|
56
|
+
* Start embedded worker.
|
|
57
|
+
*/
|
|
58
|
+
startWorker(options: ConsumerOptions): void;
|
|
59
|
+
/**
|
|
60
|
+
* Stop embedded worker.
|
|
61
|
+
*/
|
|
62
|
+
stopWorker(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Get QueueManager instance.
|
|
65
|
+
*/
|
|
66
|
+
getQueueManager(): QueueManager | undefined;
|
|
67
|
+
}
|
|
68
|
+
declare module 'hono' {
|
|
69
|
+
interface ContextVariableMap {
|
|
70
|
+
queue: QueueManager;
|
|
71
|
+
db?: unknown;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=OrbitQueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrbitQueue.d.ts","sourceRoot":"","sources":["../src/OrbitQueue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;OAEG;IACH,aAAa,CAAC,EAAE,eAAe,CAAA;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,UAAW,YAAW,YAAY;IAIjC,OAAO,CAAC,OAAO;IAH3B,OAAO,CAAC,YAAY,CAAC,CAAc;IACnC,OAAO,CAAC,QAAQ,CAAC,CAAU;gBAEP,OAAO,GAAE,iBAAsB;IAEnD;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU;IAIxD;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAqD/B;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAe3C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;OAEG;IACH,eAAe,IAAI,YAAY,GAAG,SAAS;CAG5C;AAED,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAU,kBAAkB;QAC1B,KAAK,EAAE,YAAY,CAAA;QACnB,EAAE,CAAC,EAAE,OAAO,CAAA;KACb;CACF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { QueueDriver } from './drivers/QueueDriver';
|
|
2
|
+
import type { Job } from './Job';
|
|
3
|
+
import type { Queueable } from './Queueable';
|
|
4
|
+
import type { JobSerializer } from './serializers/JobSerializer';
|
|
5
|
+
import type { QueueConfig } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Queue Manager
|
|
8
|
+
*
|
|
9
|
+
* Manages multiple queue connections and drivers, exposing a unified API for pushing and consuming jobs.
|
|
10
|
+
* Supports lazy-loading drivers to keep the core lightweight.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const manager = new QueueManager({
|
|
15
|
+
* default: 'database',
|
|
16
|
+
* connections: {
|
|
17
|
+
* database: { driver: 'database', table: 'jobs' },
|
|
18
|
+
* redis: { driver: 'redis', url: 'redis://...' }
|
|
19
|
+
* }
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* await manager.push(new SendEmail('user@example.com'))
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class QueueManager {
|
|
26
|
+
private drivers;
|
|
27
|
+
private serializers;
|
|
28
|
+
private defaultConnection;
|
|
29
|
+
private defaultSerializer;
|
|
30
|
+
constructor(config?: QueueConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Register a connection.
|
|
33
|
+
* @param name - Connection name
|
|
34
|
+
* @param config - Connection config
|
|
35
|
+
*/
|
|
36
|
+
registerConnection(name: string, config: unknown): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get a driver for a connection.
|
|
39
|
+
* @param connection - Connection name
|
|
40
|
+
* @returns Driver instance
|
|
41
|
+
*/
|
|
42
|
+
getDriver(connection: string): QueueDriver;
|
|
43
|
+
/**
|
|
44
|
+
* Get a serializer.
|
|
45
|
+
* @param type - Serializer type
|
|
46
|
+
* @returns Serializer instance
|
|
47
|
+
*/
|
|
48
|
+
getSerializer(type?: string): JobSerializer;
|
|
49
|
+
/**
|
|
50
|
+
* Register Job classes (used by ClassNameSerializer).
|
|
51
|
+
* @param jobClasses - Job class array
|
|
52
|
+
*/
|
|
53
|
+
registerJobClasses(jobClasses: Array<new (...args: unknown[]) => Job>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Push a Job to the queue.
|
|
56
|
+
* @param job - Job instance
|
|
57
|
+
* @returns The same job instance (for fluent chaining)
|
|
58
|
+
*/
|
|
59
|
+
push<T extends Job & Queueable>(job: T): Promise<T>;
|
|
60
|
+
/**
|
|
61
|
+
* Push multiple jobs.
|
|
62
|
+
* @param jobs - Job array
|
|
63
|
+
*/
|
|
64
|
+
pushMany<T extends Job & Queueable>(jobs: T[]): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Pop a job from the queue.
|
|
67
|
+
* @param queue - Queue name
|
|
68
|
+
* @param connection - Connection name
|
|
69
|
+
* @returns Job instance or null
|
|
70
|
+
*/
|
|
71
|
+
pop(queue?: string, connection?: string): Promise<Job | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Get queue size.
|
|
74
|
+
* @param queue - Queue name
|
|
75
|
+
* @param connection - Connection name
|
|
76
|
+
* @returns Number of jobs in the queue
|
|
77
|
+
*/
|
|
78
|
+
size(queue?: string, connection?: string): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Clear a queue.
|
|
81
|
+
* @param queue - Queue name
|
|
82
|
+
* @param connection - Connection name
|
|
83
|
+
*/
|
|
84
|
+
clear(queue?: string, connection?: string): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=QueueManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueueManager.d.ts","sourceRoot":"","sources":["../src/QueueManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAEhE,OAAO,KAAK,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAA;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,iBAAiB,CAAe;gBAE5B,MAAM,GAAE,WAAgB;IAwBpC;;;;OAIG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IA6FvD;;;;OAIG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW;IAQ1C;;;;OAIG;IACH,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa;IAW3C;;;OAGG;IACH,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,GAAG,CAAC,GAAG,IAAI;IAM5E;;;;OAIG;IACG,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAezD;;;OAGG;IACG,QAAQ,CAAC,CAAC,SAAS,GAAG,GAAG,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAwCnE;;;;;OAKG;IACG,GAAG,CAAC,KAAK,SAAY,EAAE,UAAU,GAAE,MAA+B,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAkB9F;;;;;OAKG;IACG,IAAI,CAAC,KAAK,SAAY,EAAE,UAAU,GAAE,MAA+B,GAAG,OAAO,CAAC,MAAM,CAAC;IAK3F;;;;OAIG;IACG,KAAK,CAAC,KAAK,SAAY,EAAE,UAAU,GAAE,MAA+B,GAAG,OAAO,CAAC,IAAI,CAAC;CAI3F"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Queueable interface.
|
|
3
|
+
*
|
|
4
|
+
* Classes implementing this interface can be pushed to a queue for execution.
|
|
5
|
+
* Provides a fluent API for queue/connection/delay configuration.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* class MyJob implements Queueable {
|
|
10
|
+
* queueName?: string
|
|
11
|
+
* connectionName?: string
|
|
12
|
+
* delaySeconds?: number
|
|
13
|
+
*
|
|
14
|
+
* onQueue(queue: string): this {
|
|
15
|
+
* this.queueName = queue
|
|
16
|
+
* return this
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* onConnection(connection: string): this {
|
|
20
|
+
* this.connectionName = connection
|
|
21
|
+
* return this
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* delay(seconds: number): this {
|
|
25
|
+
* this.delaySeconds = seconds
|
|
26
|
+
* return this
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface Queueable {
|
|
32
|
+
/**
|
|
33
|
+
* Queue name where the job should be pushed.
|
|
34
|
+
*/
|
|
35
|
+
queueName?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Connection name the job should use.
|
|
38
|
+
*/
|
|
39
|
+
connectionName?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Delay before execution (seconds).
|
|
42
|
+
*/
|
|
43
|
+
delaySeconds?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Set target queue.
|
|
46
|
+
* @param queue - Queue name
|
|
47
|
+
* @returns Self for fluent chaining
|
|
48
|
+
*/
|
|
49
|
+
onQueue(queue: string): this;
|
|
50
|
+
/**
|
|
51
|
+
* Set target connection.
|
|
52
|
+
* @param connection - Connection name
|
|
53
|
+
* @returns Self for fluent chaining
|
|
54
|
+
*/
|
|
55
|
+
onConnection(connection: string): this;
|
|
56
|
+
/**
|
|
57
|
+
* Set delay (seconds).
|
|
58
|
+
* @param delay - Delay seconds
|
|
59
|
+
* @returns Self for fluent chaining
|
|
60
|
+
*/
|
|
61
|
+
delay(delay: number): this;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=Queueable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Queueable.d.ts","sourceRoot":"","sources":["../src/Queueable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAE5B;;;;OAIG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IAEtC;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B"}
|