@things-factory/scheduler 9.0.3 → 9.0.5
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/helps/scheduler/scheduler.ko.md +279 -1
- package/helps/scheduler/scheduler.md +280 -2
- package/helps/scheduler/scheduler.zh.md +336 -57
- package/package.json +5 -5
|
@@ -5,6 +5,115 @@
|
|
|
5
5
|
- 호출된 이벤트가 실패할 경우 정책에 따라서 일정 시간 이후 재시도 수행
|
|
6
6
|
- 스케줄러 처리의 부하를 분산하기 위해서 새롭게 설계된 구조로서 스케줄러는 데이터베이스 기반의 큐 구조를 사용하여 모든 스케줄 데이터를 관리
|
|
7
7
|
|
|
8
|
+
## 🚀 독창적인 기능들
|
|
9
|
+
|
|
10
|
+
### 1. 5차원 클라이언트 식별자 시스템
|
|
11
|
+
|
|
12
|
+
스케줄러는 단순한 UUID 기반 식별을 넘어서는 독창적인 5차원 클라이언트 식별 시스템을 사용합니다:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"client": {
|
|
17
|
+
"application": "data-collection-app",
|
|
18
|
+
"group": "domain-123",
|
|
19
|
+
"type": "data-set",
|
|
20
|
+
"key": "sensor-001",
|
|
21
|
+
"operation": "collect"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**주요 장점:**
|
|
27
|
+
|
|
28
|
+
- **비즈니스 컨텍스트 인식**: 식별자가 기술적 ID가 아닌 비즈니스 의미를 반영
|
|
29
|
+
- **중복 방지**: 5개 요소가 모두 일치할 때만 동일한 스케줄로 인식
|
|
30
|
+
- **자연스러운 조직화**: application → group → type → key → operation의 계층적 구조
|
|
31
|
+
- **유연한 필터링**: 클라이언트 속성의 조합으로 스케줄 필터링 가능
|
|
32
|
+
|
|
33
|
+
### 2. 혁신적인 스케줄 타입
|
|
34
|
+
|
|
35
|
+
#### delay-recur: 혁신적인 반복 패턴
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"type": "delay-recur",
|
|
40
|
+
"schedule": "30",
|
|
41
|
+
"timezone": "UTC"
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- **간단한 반복**: 복잡한 cron 표현식 없이 30초 간격 반복
|
|
46
|
+
- **실시간 최적화**: 모니터링, 하트비트, 데이터 동기화에 완벽
|
|
47
|
+
- **리소스 효율성**: 전통적인 cron 기반 접근법보다 가벼움
|
|
48
|
+
|
|
49
|
+
#### 포괄적인 스케줄 타입 지원
|
|
50
|
+
|
|
51
|
+
- **now**: 즉시 실행
|
|
52
|
+
- **delay**: 일회성 지연 실행
|
|
53
|
+
- **date**: 특정 날짜/시간 실행
|
|
54
|
+
- **cron**: 전통적인 cron 기반 스케줄링
|
|
55
|
+
- **delay-recur**: 혁신적인 반복 패턴
|
|
56
|
+
|
|
57
|
+
### 3. 고급 실패 처리
|
|
58
|
+
|
|
59
|
+
#### retry_dlq: 하이브리드 실패 정책
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"failed_policy": "retry_dlq",
|
|
64
|
+
"retry_wait": 60,
|
|
65
|
+
"max_retry_count": 3
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**3단계 실패 처리:**
|
|
70
|
+
|
|
71
|
+
1. **즉시 재시도**: 지수 백오프를 통한 빠른 재시도
|
|
72
|
+
2. **최대 재시도**: 설정된 최대 시도 횟수까지
|
|
73
|
+
3. **Dead Letter Queue**: 실패한 작업을 DLQ로 이동하여 나중에 처리
|
|
74
|
+
|
|
75
|
+
**장점:**
|
|
76
|
+
|
|
77
|
+
- **시스템 안정성**: 무한 재시도 루프 방지
|
|
78
|
+
- **데이터 보존**: 실패 시에도 데이터 손실 없음
|
|
79
|
+
- **문제 진단**: DLQ를 통한 실패 원인 분석 가능
|
|
80
|
+
|
|
81
|
+
### 4. 히스토리 인식 스케줄링
|
|
82
|
+
|
|
83
|
+
#### history_check: 실행 히스토리 관리
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"history_check": true
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**기능:**
|
|
92
|
+
|
|
93
|
+
- **중복 방지**: 이미 완료된 작업의 재실행 방지
|
|
94
|
+
- **상태 기반 의사결정**: 실행 히스토리를 기반으로 한 스케줄링 결정
|
|
95
|
+
- **감사 추적**: 규정 준수 및 디버깅을 위한 완전한 실행 히스토리
|
|
96
|
+
|
|
97
|
+
### 5. 도메인 인식 콜백 시스템
|
|
98
|
+
|
|
99
|
+
#### 멀티 테넌트 지원
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"task": {
|
|
104
|
+
"connection": {
|
|
105
|
+
"host": "http://localhost:3000/domain/company/callback-schedule-for-dataset"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**장점:**
|
|
112
|
+
|
|
113
|
+
- **테넌트 격리**: 각 도메인의 스케줄이 독립적으로 처리
|
|
114
|
+
- **자동 URL 생성**: 도메인 컨텍스트가 콜백 URL에 자동 포함
|
|
115
|
+
- **보안**: 도메인 기반 접근 제어 및 데이터 격리
|
|
116
|
+
|
|
8
117
|
### 스케줄러의 주기적 처리에 대한 Diagram
|
|
9
118
|
|
|
10
119
|

|
|
@@ -34,11 +143,107 @@
|
|
|
34
143
|
- 스케줄러 서비스는 Restful 기반의 수평 확장이 가능한 스케줄러 서비스.
|
|
35
144
|
- MSA 기반의 어플리케이션 환경에서 기존 어플리케이션이 수행하는 스케줄링 모듈에 대해서, 별도의 스케줄링 서비스를 분리해서 제공하는 서비스를 제공합니다.
|
|
36
145
|
|
|
146
|
+
## 🎯 사용 사례 및 모범 사례
|
|
147
|
+
|
|
148
|
+
### 실시간 모니터링
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"name": "sensor-monitoring",
|
|
153
|
+
"client": {
|
|
154
|
+
"application": "iot-platform",
|
|
155
|
+
"group": "factory-001",
|
|
156
|
+
"type": "sensor",
|
|
157
|
+
"key": "temperature-sensor-01",
|
|
158
|
+
"operation": "monitor"
|
|
159
|
+
},
|
|
160
|
+
"type": "delay-recur",
|
|
161
|
+
"schedule": "30",
|
|
162
|
+
"timezone": "Asia/Seoul",
|
|
163
|
+
"task": {
|
|
164
|
+
"type": "rest",
|
|
165
|
+
"connection": {
|
|
166
|
+
"host": "http://localhost:3000/api/sensor/collect",
|
|
167
|
+
"headers": { "Content-Type": "application/json" }
|
|
168
|
+
},
|
|
169
|
+
"data": { "sensorId": "temp-001", "threshold": 25 },
|
|
170
|
+
"history_check": true,
|
|
171
|
+
"failed_policy": "retry_dlq",
|
|
172
|
+
"retry_wait": 60,
|
|
173
|
+
"max_retry_count": 3
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 데이터 동기화
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"name": "data-sync",
|
|
183
|
+
"client": {
|
|
184
|
+
"application": "erp-system",
|
|
185
|
+
"group": "company-abc",
|
|
186
|
+
"type": "inventory",
|
|
187
|
+
"key": "daily-sync",
|
|
188
|
+
"operation": "sync"
|
|
189
|
+
},
|
|
190
|
+
"type": "cron",
|
|
191
|
+
"schedule": "0 2 * * *",
|
|
192
|
+
"timezone": "Asia/Seoul",
|
|
193
|
+
"task": {
|
|
194
|
+
"type": "kafka",
|
|
195
|
+
"connection": {
|
|
196
|
+
"host": "localhost:9092",
|
|
197
|
+
"topic": "inventory-sync"
|
|
198
|
+
},
|
|
199
|
+
"data": { "syncType": "full", "timestamp": "2024-01-01T02:00:00Z" },
|
|
200
|
+
"history_check": true,
|
|
201
|
+
"failed_policy": "retry_dlq",
|
|
202
|
+
"retry_wait": 300,
|
|
203
|
+
"max_retry_count": 5
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 보고서 생성
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"name": "daily-report",
|
|
213
|
+
"client": {
|
|
214
|
+
"application": "analytics-platform",
|
|
215
|
+
"group": "marketing-team",
|
|
216
|
+
"type": "report",
|
|
217
|
+
"key": "daily-metrics",
|
|
218
|
+
"operation": "generate"
|
|
219
|
+
},
|
|
220
|
+
"type": "cron",
|
|
221
|
+
"schedule": "0 9 * * 1-5",
|
|
222
|
+
"timezone": "Asia/Seoul",
|
|
223
|
+
"task": {
|
|
224
|
+
"type": "rest",
|
|
225
|
+
"connection": {
|
|
226
|
+
"host": "http://localhost:3000/api/reports/generate",
|
|
227
|
+
"headers": { "Authorization": "Bearer ..." }
|
|
228
|
+
},
|
|
229
|
+
"data": { "reportType": "daily", "recipients": ["team@company.com"] },
|
|
230
|
+
"history_check": true,
|
|
231
|
+
"failed_policy": "retry",
|
|
232
|
+
"retry_wait": 1800,
|
|
233
|
+
"max_retry_count": 2
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
37
238
|
## 사용 가능한 용도
|
|
38
239
|
|
|
39
240
|
- 크론(cron) 기반의 스케줄잡(Schedule Job) 핸들러
|
|
40
241
|
- 특정한 날짜 혹은 특정한 주기로 실행되는 태스크 실행 엔진
|
|
41
242
|
- 특정한 이벤트를 등록 관리하고, 이벤트를 기반으로 특정 기능을 실행하거나 데이터를 전달하는 브로커
|
|
243
|
+
- **실시간 모니터링**: delay-recur를 사용한 짧은 간격의 연속 모니터링
|
|
244
|
+
- **데이터 동기화**: 시스템 간의 주기적 데이터 동기화
|
|
245
|
+
- **보고서 생성**: 자동화된 보고서 생성 및 배포
|
|
246
|
+
- **IoT 디바이스 관리**: IoT 디바이스 통신 및 데이터 수집 관리
|
|
42
247
|
|
|
43
248
|
### Schedule
|
|
44
249
|
|
|
@@ -119,7 +324,6 @@
|
|
|
119
324
|
```
|
|
120
325
|
|
|
121
326
|
- cron: cron format을 기반으로 스케줄이 동작합니다.
|
|
122
|
-
|
|
123
327
|
- 기본적인 5개 포맷을 사용합니다.
|
|
124
328
|
- 초 단위 스케줄리을 실행하기 위해서는 6개 시간 요소가 필요하면, 첫번째 요소가 초를 지정합니다.
|
|
125
329
|
|
|
@@ -183,3 +387,77 @@
|
|
|
183
387
|
}
|
|
184
388
|
}
|
|
185
389
|
```
|
|
390
|
+
|
|
391
|
+
## 🔧 고급 설정
|
|
392
|
+
|
|
393
|
+
### 재시도 정책
|
|
394
|
+
|
|
395
|
+
#### ignore
|
|
396
|
+
|
|
397
|
+
- 재시도 시도 없음
|
|
398
|
+
- 중요하지 않은 작업에 적합
|
|
399
|
+
|
|
400
|
+
#### retry
|
|
401
|
+
|
|
402
|
+
- 지수 백오프를 통한 단순 재시도
|
|
403
|
+
- 일시적 실패에 좋음
|
|
404
|
+
|
|
405
|
+
#### retry_dlq
|
|
406
|
+
|
|
407
|
+
- Dead Letter Queue 폴백을 통한 재시도
|
|
408
|
+
- 데이터 보존이 필요한 중요 작업에 최적
|
|
409
|
+
|
|
410
|
+
### 히스토리 체크 설정
|
|
411
|
+
|
|
412
|
+
#### true
|
|
413
|
+
|
|
414
|
+
- 중복 실행 방지
|
|
415
|
+
- 실행 히스토리 유지
|
|
416
|
+
- 데이터 수집 및 보고서에 적합
|
|
417
|
+
|
|
418
|
+
#### false
|
|
419
|
+
|
|
420
|
+
- 다중 실행 허용
|
|
421
|
+
- 히스토리 추적 없음
|
|
422
|
+
- 실시간 모니터링에 적합
|
|
423
|
+
|
|
424
|
+
### 타임존 고려사항
|
|
425
|
+
|
|
426
|
+
- **글로벌 배포**: 다중 타임존 지원
|
|
427
|
+
- **업무 시간**: 현지 업무 시간 기준 스케줄 실행
|
|
428
|
+
- **DST 처리**: 자동 일광절약시간 조정
|
|
429
|
+
|
|
430
|
+
## 🚀 성능 최적화
|
|
431
|
+
|
|
432
|
+
### 모범 사례
|
|
433
|
+
|
|
434
|
+
1. **짧은 간격에는 delay-recur 사용**: 빈번한 작업에 cron보다 효율적
|
|
435
|
+
2. **데이터 작업에는 history_check 구현**: 중복 데이터 처리 방지
|
|
436
|
+
3. **적절한 재시도 정책 구성**: 신뢰성과 성능의 균형
|
|
437
|
+
4. **타임존 인식 스케줄링 사용**: 정확한 실행 시간 보장
|
|
438
|
+
5. **DLQ 모니터링**: 정기적으로 실패한 작업 확인 및 처리
|
|
439
|
+
|
|
440
|
+
### 확장 고려사항
|
|
441
|
+
|
|
442
|
+
- **수평 확장**: 여러 스케줄러 인스턴스가 동시에 실행 가능
|
|
443
|
+
- **부하 분산**: 데이터베이스 기반 큐가 인스턴스 간 부하 분산
|
|
444
|
+
- **장애 복구 지원**: 인스턴스 다운 시 자동 장애 복구
|
|
445
|
+
- **리소스 관리**: 지능형 스케줄링을 통한 효율적인 리소스 활용
|
|
446
|
+
|
|
447
|
+
## 🔍 모니터링 및 문제 해결
|
|
448
|
+
|
|
449
|
+
### 모니터링해야 할 주요 지표
|
|
450
|
+
|
|
451
|
+
- **실행 성공률**: 성공적인 작업 실행 비율
|
|
452
|
+
- **재시도 빈도**: 작업당 재시도 횟수
|
|
453
|
+
- **DLQ 크기**: Dead Letter Queue의 작업 수
|
|
454
|
+
- **실행 시간**: 작업 완료 평균 시간
|
|
455
|
+
- **스케줄 정확도**: 예상 실행 시간과의 편차
|
|
456
|
+
|
|
457
|
+
### 일반적인 문제 및 해결책
|
|
458
|
+
|
|
459
|
+
1. **높은 재시도율**: 네트워크 연결성 및 대상 서비스 가용성 확인
|
|
460
|
+
2. **DLQ 오버플로우**: 실패한 작업 검토 및 근본 원인 수정
|
|
461
|
+
3. **실행 누락**: 타임존 설정 및 스케줄 표현식 확인
|
|
462
|
+
4. **성능 문제**: 빈번한 작업에는 delay-recur 사용 고려
|
|
463
|
+
5. **중복 실행**: 적절한 작업에 history_check 활성화
|
|
@@ -5,6 +5,115 @@
|
|
|
5
5
|
- If an invoked event fails, it retries after a certain period, as defined by the policy.
|
|
6
6
|
- To distribute the load of scheduler processing, a newly designed structure uses a database-based queue to manage all schedule data.
|
|
7
7
|
|
|
8
|
+
## 🚀 Unique Features
|
|
9
|
+
|
|
10
|
+
### 1. Five-Dimensional Client Identifier System
|
|
11
|
+
|
|
12
|
+
The scheduler uses a unique 5-dimensional client identification system that goes beyond simple UUID-based identification:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"client": {
|
|
17
|
+
"application": "data-collection-app",
|
|
18
|
+
"group": "domain-123",
|
|
19
|
+
"type": "data-set",
|
|
20
|
+
"key": "sensor-001",
|
|
21
|
+
"operation": "collect"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Key Benefits:**
|
|
27
|
+
|
|
28
|
+
- **Business Context Awareness**: Identifiers reflect business meaning rather than technical IDs
|
|
29
|
+
- **Duplicate Prevention**: Only schedules with all 5 elements matching are considered identical
|
|
30
|
+
- **Natural Organization**: Hierarchical organization from application → group → type → key → operation
|
|
31
|
+
- **Flexible Filtering**: Filter schedules by any combination of client properties
|
|
32
|
+
|
|
33
|
+
### 2. Innovative Schedule Types
|
|
34
|
+
|
|
35
|
+
#### delay-recur: Revolutionary Recurring Pattern
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"type": "delay-recur",
|
|
40
|
+
"schedule": "30",
|
|
41
|
+
"timezone": "UTC"
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- **Simple Recurrence**: 30-second intervals without complex cron expressions
|
|
46
|
+
- **Real-time Optimization**: Perfect for monitoring, heartbeat, and data synchronization
|
|
47
|
+
- **Resource Efficiency**: Lightweight compared to traditional cron-based approaches
|
|
48
|
+
|
|
49
|
+
#### Comprehensive Schedule Type Support
|
|
50
|
+
|
|
51
|
+
- **now**: Immediate execution
|
|
52
|
+
- **delay**: One-time delayed execution
|
|
53
|
+
- **date**: Specific date/time execution
|
|
54
|
+
- **cron**: Traditional cron-based scheduling
|
|
55
|
+
- **delay-recur**: Innovative recurring pattern
|
|
56
|
+
|
|
57
|
+
### 3. Advanced Failure Handling
|
|
58
|
+
|
|
59
|
+
#### retry_dlq: Hybrid Failure Policy
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"failed_policy": "retry_dlq",
|
|
64
|
+
"retry_wait": 60,
|
|
65
|
+
"max_retry_count": 3
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Three-Stage Failure Handling:**
|
|
70
|
+
|
|
71
|
+
1. **Immediate Retry**: Quick retry with exponential backoff
|
|
72
|
+
2. **Maximum Retries**: Up to configured maximum attempts
|
|
73
|
+
3. **Dead Letter Queue**: Failed tasks moved to DLQ for later processing
|
|
74
|
+
|
|
75
|
+
**Benefits:**
|
|
76
|
+
|
|
77
|
+
- **System Stability**: Prevents infinite retry loops
|
|
78
|
+
- **Data Preservation**: No data loss even with failures
|
|
79
|
+
- **Problem Diagnosis**: DLQ enables failure analysis
|
|
80
|
+
|
|
81
|
+
### 4. History-Aware Scheduling
|
|
82
|
+
|
|
83
|
+
#### history_check: Execution History Management
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"history_check": true
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Features:**
|
|
92
|
+
|
|
93
|
+
- **Duplicate Prevention**: Avoids re-executing already completed tasks
|
|
94
|
+
- **State-Based Decisions**: Makes scheduling decisions based on execution history
|
|
95
|
+
- **Audit Trail**: Complete execution history for compliance and debugging
|
|
96
|
+
|
|
97
|
+
### 5. Domain-Aware Callback System
|
|
98
|
+
|
|
99
|
+
#### Multi-Tenant Support
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"task": {
|
|
104
|
+
"connection": {
|
|
105
|
+
"host": "http://localhost:3000/domain/company/callback-schedule-for-dataset"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Benefits:**
|
|
112
|
+
|
|
113
|
+
- **Tenant Isolation**: Each domain's schedules are processed independently
|
|
114
|
+
- **Automatic URL Generation**: Domain context automatically included in callback URLs
|
|
115
|
+
- **Security**: Domain-based access control and data isolation
|
|
116
|
+
|
|
8
117
|
### Diagram for Periodic Processing in the Scheduler
|
|
9
118
|
|
|
10
119
|

|
|
@@ -24,7 +133,7 @@
|
|
|
24
133
|

|
|
25
134
|
|
|
26
135
|
- The traditional application structure for processing scheduling jobs cannot function in a cloud-based horizontal scaling architecture.
|
|
27
|
-
- A separate scheduler service is needed. While there are many services for such tasks, there isn
|
|
136
|
+
- A separate scheduler service is needed. While there are many services for such tasks, there isn't a dedicated service solely for the role of scheduling.
|
|
28
137
|
- A scalable service that can be horizontally expanded in a cloud environment is required.
|
|
29
138
|
|
|
30
139
|
## Service Overview
|
|
@@ -34,11 +143,107 @@
|
|
|
34
143
|
- Scheduler service is a horizontally scalable scheduling service based on RESTful architecture.
|
|
35
144
|
- It provides a service that separates scheduling modules from existing applications in MSA-based environments.
|
|
36
145
|
|
|
146
|
+
## 🎯 Use Cases and Best Practices
|
|
147
|
+
|
|
148
|
+
### Real-Time Monitoring
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"name": "sensor-monitoring",
|
|
153
|
+
"client": {
|
|
154
|
+
"application": "iot-platform",
|
|
155
|
+
"group": "factory-001",
|
|
156
|
+
"type": "sensor",
|
|
157
|
+
"key": "temperature-sensor-01",
|
|
158
|
+
"operation": "monitor"
|
|
159
|
+
},
|
|
160
|
+
"type": "delay-recur",
|
|
161
|
+
"schedule": "30",
|
|
162
|
+
"timezone": "Asia/Seoul",
|
|
163
|
+
"task": {
|
|
164
|
+
"type": "rest",
|
|
165
|
+
"connection": {
|
|
166
|
+
"host": "http://localhost:3000/api/sensor/collect",
|
|
167
|
+
"headers": { "Content-Type": "application/json" }
|
|
168
|
+
},
|
|
169
|
+
"data": { "sensorId": "temp-001", "threshold": 25 },
|
|
170
|
+
"history_check": true,
|
|
171
|
+
"failed_policy": "retry_dlq",
|
|
172
|
+
"retry_wait": 60,
|
|
173
|
+
"max_retry_count": 3
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Data Synchronization
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"name": "data-sync",
|
|
183
|
+
"client": {
|
|
184
|
+
"application": "erp-system",
|
|
185
|
+
"group": "company-abc",
|
|
186
|
+
"type": "inventory",
|
|
187
|
+
"key": "daily-sync",
|
|
188
|
+
"operation": "sync"
|
|
189
|
+
},
|
|
190
|
+
"type": "cron",
|
|
191
|
+
"schedule": "0 2 * * *",
|
|
192
|
+
"timezone": "Asia/Seoul",
|
|
193
|
+
"task": {
|
|
194
|
+
"type": "kafka",
|
|
195
|
+
"connection": {
|
|
196
|
+
"host": "localhost:9092",
|
|
197
|
+
"topic": "inventory-sync"
|
|
198
|
+
},
|
|
199
|
+
"data": { "syncType": "full", "timestamp": "2024-01-01T02:00:00Z" },
|
|
200
|
+
"history_check": true,
|
|
201
|
+
"failed_policy": "retry_dlq",
|
|
202
|
+
"retry_wait": 300,
|
|
203
|
+
"max_retry_count": 5
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Report Generation
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"name": "daily-report",
|
|
213
|
+
"client": {
|
|
214
|
+
"application": "analytics-platform",
|
|
215
|
+
"group": "marketing-team",
|
|
216
|
+
"type": "report",
|
|
217
|
+
"key": "daily-metrics",
|
|
218
|
+
"operation": "generate"
|
|
219
|
+
},
|
|
220
|
+
"type": "cron",
|
|
221
|
+
"schedule": "0 9 * * 1-5",
|
|
222
|
+
"timezone": "Asia/Seoul",
|
|
223
|
+
"task": {
|
|
224
|
+
"type": "rest",
|
|
225
|
+
"connection": {
|
|
226
|
+
"host": "http://localhost:3000/api/reports/generate",
|
|
227
|
+
"headers": { "Authorization": "Bearer ..." }
|
|
228
|
+
},
|
|
229
|
+
"data": { "reportType": "daily", "recipients": ["team@company.com"] },
|
|
230
|
+
"history_check": true,
|
|
231
|
+
"failed_policy": "retry",
|
|
232
|
+
"retry_wait": 1800,
|
|
233
|
+
"max_retry_count": 2
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
37
238
|
## Usable Scenarios
|
|
38
239
|
|
|
39
240
|
- **Cron-Based Schedule Job Handlers**: For processing tasks at specific intervals.
|
|
40
241
|
- **Task Execution Engines**: For executing tasks on specific dates or at specific intervals.
|
|
41
242
|
- **Event-Driven Task Handlers**: For registering and managing events, and executing specific tasks or transferring data based on those events.
|
|
243
|
+
- **Real-Time Monitoring**: For continuous monitoring with short intervals using delay-recur.
|
|
244
|
+
- **Data Synchronization**: For periodic data synchronization between systems.
|
|
245
|
+
- **Report Generation**: For automated report generation and distribution.
|
|
246
|
+
- **IoT Device Management**: For managing IoT device communication and data collection.
|
|
42
247
|
|
|
43
248
|
### Schedule
|
|
44
249
|
|
|
@@ -119,7 +324,6 @@ An example of the format for registering a schedule is as follows:
|
|
|
119
324
|
```
|
|
120
325
|
|
|
121
326
|
- **cron**: Operates based on the cron format.
|
|
122
|
-
|
|
123
327
|
- Uses the basic five-element format.
|
|
124
328
|
- For second-level schedules, a six-element format is required, where the first element specifies seconds.
|
|
125
329
|
|
|
@@ -184,3 +388,77 @@ An example of the format for registering a schedule is as follows:
|
|
|
184
388
|
}
|
|
185
389
|
}
|
|
186
390
|
```
|
|
391
|
+
|
|
392
|
+
## 🔧 Advanced Configuration
|
|
393
|
+
|
|
394
|
+
### Retry Policies
|
|
395
|
+
|
|
396
|
+
#### ignore
|
|
397
|
+
|
|
398
|
+
- No retry attempts
|
|
399
|
+
- Suitable for non-critical tasks
|
|
400
|
+
|
|
401
|
+
#### retry
|
|
402
|
+
|
|
403
|
+
- Simple retry with exponential backoff
|
|
404
|
+
- Good for transient failures
|
|
405
|
+
|
|
406
|
+
#### retry_dlq
|
|
407
|
+
|
|
408
|
+
- Retry with Dead Letter Queue fallback
|
|
409
|
+
- Best for critical tasks requiring data preservation
|
|
410
|
+
|
|
411
|
+
### History Check Configuration
|
|
412
|
+
|
|
413
|
+
#### true
|
|
414
|
+
|
|
415
|
+
- Prevents duplicate execution
|
|
416
|
+
- Maintains execution history
|
|
417
|
+
- Suitable for data collection and reporting
|
|
418
|
+
|
|
419
|
+
#### false
|
|
420
|
+
|
|
421
|
+
- Allows multiple executions
|
|
422
|
+
- No history tracking
|
|
423
|
+
- Suitable for real-time monitoring
|
|
424
|
+
|
|
425
|
+
### Timezone Considerations
|
|
426
|
+
|
|
427
|
+
- **Global Deployment**: Support for multiple timezones
|
|
428
|
+
- **Business Hours**: Schedule execution based on local business hours
|
|
429
|
+
- **DST Handling**: Automatic daylight saving time adjustments
|
|
430
|
+
|
|
431
|
+
## 🚀 Performance Optimization
|
|
432
|
+
|
|
433
|
+
### Best Practices
|
|
434
|
+
|
|
435
|
+
1. **Use delay-recur for short intervals**: More efficient than cron for frequent tasks
|
|
436
|
+
2. **Implement history_check for data tasks**: Prevents duplicate data processing
|
|
437
|
+
3. **Configure appropriate retry policies**: Balance between reliability and performance
|
|
438
|
+
4. **Use timezone-aware scheduling**: Ensure accurate execution times
|
|
439
|
+
5. **Monitor DLQ**: Regularly check and process failed tasks
|
|
440
|
+
|
|
441
|
+
### Scaling Considerations
|
|
442
|
+
|
|
443
|
+
- **Horizontal Scaling**: Multiple scheduler instances can run simultaneously
|
|
444
|
+
- **Load Distribution**: Database-based queue distributes load across instances
|
|
445
|
+
- **Failover Support**: Automatic failover when instances go down
|
|
446
|
+
- **Resource Management**: Efficient resource utilization through intelligent scheduling
|
|
447
|
+
|
|
448
|
+
## 🔍 Monitoring and Troubleshooting
|
|
449
|
+
|
|
450
|
+
### Key Metrics to Monitor
|
|
451
|
+
|
|
452
|
+
- **Execution Success Rate**: Percentage of successful task executions
|
|
453
|
+
- **Retry Frequency**: Number of retries per task
|
|
454
|
+
- **DLQ Size**: Number of tasks in Dead Letter Queue
|
|
455
|
+
- **Execution Time**: Average time for task completion
|
|
456
|
+
- **Schedule Accuracy**: Deviation from expected execution times
|
|
457
|
+
|
|
458
|
+
### Common Issues and Solutions
|
|
459
|
+
|
|
460
|
+
1. **High Retry Rate**: Check network connectivity and target service availability
|
|
461
|
+
2. **DLQ Overflow**: Review failed tasks and fix underlying issues
|
|
462
|
+
3. **Missed Executions**: Verify timezone settings and schedule expressions
|
|
463
|
+
4. **Performance Issues**: Consider using delay-recur for frequent tasks
|
|
464
|
+
5. **Duplicate Executions**: Enable history_check for appropriate tasks
|
|
@@ -1,50 +1,255 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 调度器服务
|
|
2
2
|
|
|
3
|
-
-
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
3
|
+
- 在调度器中注册的所有事件都使用各种调度类型和值(包括cron)进行指定
|
|
4
|
+
- 根据用户指定的调度类型调用事件,通常调用的事件会调用注册时指定的REST API
|
|
5
|
+
- 如果调用的事件失败,会根据策略在特定时间后重试
|
|
6
|
+
- 为了分散调度器处理的负载,新设计的结构使用基于数据库的队列来管理所有调度数据
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## 🚀 独特功能
|
|
9
|
+
|
|
10
|
+
### 1. 五维客户端标识符系统
|
|
11
|
+
|
|
12
|
+
调度器使用独特的五维客户端标识系统,超越了简单的基于UUID的标识:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"client": {
|
|
17
|
+
"application": "data-collection-app",
|
|
18
|
+
"group": "domain-123",
|
|
19
|
+
"type": "data-set",
|
|
20
|
+
"key": "sensor-001",
|
|
21
|
+
"operation": "collect"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**主要优势:**
|
|
27
|
+
|
|
28
|
+
- **业务上下文感知**:标识符反映业务含义而非技术ID
|
|
29
|
+
- **重复防止**:只有5个元素都匹配的调度才被认为是相同的
|
|
30
|
+
- **自然组织**:从application → group → type → key → operation的层次结构
|
|
31
|
+
- **灵活过滤**:通过客户端属性的任意组合过滤调度
|
|
32
|
+
|
|
33
|
+
### 2. 创新的调度类型
|
|
34
|
+
|
|
35
|
+
#### delay-recur:革命性的重复模式
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"type": "delay-recur",
|
|
40
|
+
"schedule": "30",
|
|
41
|
+
"timezone": "UTC"
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- **简单重复**:30秒间隔,无需复杂的cron表达式
|
|
46
|
+
- **实时优化**:完美适用于监控、心跳和数据同步
|
|
47
|
+
- **资源效率**:比传统的基于cron的方法更轻量
|
|
48
|
+
|
|
49
|
+
#### 全面的调度类型支持
|
|
50
|
+
|
|
51
|
+
- **now**:立即执行
|
|
52
|
+
- **delay**:一次性延迟执行
|
|
53
|
+
- **date**:特定日期/时间执行
|
|
54
|
+
- **cron**:传统的基于cron的调度
|
|
55
|
+
- **delay-recur**:创新的重复模式
|
|
56
|
+
|
|
57
|
+
### 3. 高级失败处理
|
|
58
|
+
|
|
59
|
+
#### retry_dlq:混合失败策略
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"failed_policy": "retry_dlq",
|
|
64
|
+
"retry_wait": 60,
|
|
65
|
+
"max_retry_count": 3
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**三阶段失败处理:**
|
|
70
|
+
|
|
71
|
+
1. **立即重试**:通过指数退避进行快速重试
|
|
72
|
+
2. **最大重试**:最多配置的最大尝试次数
|
|
73
|
+
3. **死信队列**:失败的任务移动到DLQ以便稍后处理
|
|
74
|
+
|
|
75
|
+
**优势:**
|
|
76
|
+
|
|
77
|
+
- **系统稳定性**:防止无限重试循环
|
|
78
|
+
- **数据保护**:即使失败也不会丢失数据
|
|
79
|
+
- **问题诊断**:DLQ支持失败分析
|
|
80
|
+
|
|
81
|
+
### 4. 历史感知调度
|
|
82
|
+
|
|
83
|
+
#### history_check:执行历史管理
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"history_check": true
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**功能:**
|
|
92
|
+
|
|
93
|
+
- **重复防止**:避免重新执行已完成的任务
|
|
94
|
+
- **基于状态的决策**:基于执行历史做出调度决策
|
|
95
|
+
- **审计跟踪**:用于合规和调试的完整执行历史
|
|
96
|
+
|
|
97
|
+
### 5. 域感知回调系统
|
|
98
|
+
|
|
99
|
+
#### 多租户支持
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"task": {
|
|
104
|
+
"connection": {
|
|
105
|
+
"host": "http://localhost:3000/domain/company/callback-schedule-for-dataset"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**优势:**
|
|
112
|
+
|
|
113
|
+
- **租户隔离**:每个域的调度独立处理
|
|
114
|
+
- **自动URL生成**:域上下文自动包含在回调URL中
|
|
115
|
+
- **安全性**:基于域的访问控制和数据隔离
|
|
116
|
+
|
|
117
|
+
### 调度器周期性处理的图表
|
|
9
118
|
|
|
10
119
|

|
|
11
120
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
121
|
+
- **优势**:结构简单,无需额外服务即可运行
|
|
122
|
+
- **劣势**:每个实例必须周期性唤醒并检查数据库中的调度队列,无空闲期
|
|
14
123
|
|
|
15
|
-
###
|
|
124
|
+
### 替代方案:监控实例周期性检查调度器唤醒时间并向所有调度器发布的结构
|
|
16
125
|
|
|
17
126
|

|
|
18
127
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
128
|
+
- 所有实例基于从监控实例接收的下一个调度时间戳信息处理调度
|
|
129
|
+
- **要求**:需要额外服务(如Redis),每个实例必须持续持有下一个调度的信息
|
|
21
130
|
|
|
22
|
-
## MSA
|
|
131
|
+
## MSA中的调度器服务
|
|
23
132
|
|
|
24
133
|

|
|
25
134
|
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
135
|
+
- 传统应用程序结构中处理调度作业的调度器服务无法在基于云的水平扩展架构中运行
|
|
136
|
+
- 需要单独的调度器服务。虽然有许多此类任务的服务,但没有专门仅用于调度角色的服务
|
|
137
|
+
- 需要可在云环境中水平扩展的可扩展服务
|
|
29
138
|
|
|
30
|
-
##
|
|
139
|
+
## 服务概述
|
|
31
140
|
|
|
32
141
|

|
|
33
142
|
|
|
34
|
-
-
|
|
35
|
-
- MSA
|
|
143
|
+
- 调度器服务是基于RESTful架构的水平可扩展调度服务
|
|
144
|
+
- 它提供了一种服务,在基于MSA的应用程序环境中将调度模块与现有应用程序分离
|
|
36
145
|
|
|
37
|
-
##
|
|
146
|
+
## 🎯 使用案例和最佳实践
|
|
38
147
|
|
|
39
|
-
|
|
40
|
-
- 특정한 날짜 혹은 특정한 주기로 실행되는 태스크 실행 엔진
|
|
41
|
-
- 특정한 이벤트를 등록 관리하고, 이벤트를 기반으로 특정 기능을 실행하거나 데이터를 전달하는 브로커
|
|
148
|
+
### 实时监控
|
|
42
149
|
|
|
43
|
-
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"name": "sensor-monitoring",
|
|
153
|
+
"client": {
|
|
154
|
+
"application": "iot-platform",
|
|
155
|
+
"group": "factory-001",
|
|
156
|
+
"type": "sensor",
|
|
157
|
+
"key": "temperature-sensor-01",
|
|
158
|
+
"operation": "monitor"
|
|
159
|
+
},
|
|
160
|
+
"type": "delay-recur",
|
|
161
|
+
"schedule": "30",
|
|
162
|
+
"timezone": "Asia/Seoul",
|
|
163
|
+
"task": {
|
|
164
|
+
"type": "rest",
|
|
165
|
+
"connection": {
|
|
166
|
+
"host": "http://localhost:3000/api/sensor/collect",
|
|
167
|
+
"headers": { "Content-Type": "application/json" }
|
|
168
|
+
},
|
|
169
|
+
"data": { "sensorId": "temp-001", "threshold": 25 },
|
|
170
|
+
"history_check": true,
|
|
171
|
+
"failed_policy": "retry_dlq",
|
|
172
|
+
"retry_wait": 60,
|
|
173
|
+
"max_retry_count": 3
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 数据同步
|
|
44
179
|
|
|
45
|
-
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"name": "data-sync",
|
|
183
|
+
"client": {
|
|
184
|
+
"application": "erp-system",
|
|
185
|
+
"group": "company-abc",
|
|
186
|
+
"type": "inventory",
|
|
187
|
+
"key": "daily-sync",
|
|
188
|
+
"operation": "sync"
|
|
189
|
+
},
|
|
190
|
+
"type": "cron",
|
|
191
|
+
"schedule": "0 2 * * *",
|
|
192
|
+
"timezone": "Asia/Seoul",
|
|
193
|
+
"task": {
|
|
194
|
+
"type": "kafka",
|
|
195
|
+
"connection": {
|
|
196
|
+
"host": "localhost:9092",
|
|
197
|
+
"topic": "inventory-sync"
|
|
198
|
+
},
|
|
199
|
+
"data": { "syncType": "full", "timestamp": "2024-01-01T02:00:00Z" },
|
|
200
|
+
"history_check": true,
|
|
201
|
+
"failed_policy": "retry_dlq",
|
|
202
|
+
"retry_wait": 300,
|
|
203
|
+
"max_retry_count": 5
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
46
207
|
|
|
47
|
-
|
|
208
|
+
### 报告生成
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"name": "daily-report",
|
|
213
|
+
"client": {
|
|
214
|
+
"application": "analytics-platform",
|
|
215
|
+
"group": "marketing-team",
|
|
216
|
+
"type": "report",
|
|
217
|
+
"key": "daily-metrics",
|
|
218
|
+
"operation": "generate"
|
|
219
|
+
},
|
|
220
|
+
"type": "cron",
|
|
221
|
+
"schedule": "0 9 * * 1-5",
|
|
222
|
+
"timezone": "Asia/Seoul",
|
|
223
|
+
"task": {
|
|
224
|
+
"type": "rest",
|
|
225
|
+
"connection": {
|
|
226
|
+
"host": "http://localhost:3000/api/reports/generate",
|
|
227
|
+
"headers": { "Authorization": "Bearer ..." }
|
|
228
|
+
},
|
|
229
|
+
"data": { "reportType": "daily", "recipients": ["team@company.com"] },
|
|
230
|
+
"history_check": true,
|
|
231
|
+
"failed_policy": "retry",
|
|
232
|
+
"retry_wait": 1800,
|
|
233
|
+
"max_retry_count": 2
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 可用场景
|
|
239
|
+
|
|
240
|
+
- **基于Cron的调度作业处理器**:用于在特定间隔处理任务
|
|
241
|
+
- **任务执行引擎**:用于在特定日期或特定间隔执行任务
|
|
242
|
+
- **事件驱动的任务处理器**:用于注册和管理事件,并基于这些事件执行特定任务或传输数据
|
|
243
|
+
- **实时监控**:使用delay-recur进行短间隔的连续监控
|
|
244
|
+
- **数据同步**:系统间的周期性数据同步
|
|
245
|
+
- **报告生成**:自动化报告生成和分发
|
|
246
|
+
- **IoT设备管理**:管理IoT设备通信和数据收集
|
|
247
|
+
|
|
248
|
+
### 调度
|
|
249
|
+
|
|
250
|
+
#### 格式
|
|
251
|
+
|
|
252
|
+
注册调度的格式示例如下:
|
|
48
253
|
|
|
49
254
|
```json
|
|
50
255
|
{
|
|
@@ -73,28 +278,28 @@
|
|
|
73
278
|
}
|
|
74
279
|
```
|
|
75
280
|
|
|
76
|
-
- name
|
|
77
|
-
- client
|
|
78
|
-
- operation
|
|
79
|
-
- application
|
|
80
|
-
- group
|
|
81
|
-
- key
|
|
82
|
-
-
|
|
83
|
-
- type
|
|
84
|
-
- schedule
|
|
85
|
-
- timezone
|
|
86
|
-
- task
|
|
87
|
-
- type
|
|
88
|
-
- connection
|
|
89
|
-
- host
|
|
90
|
-
- topic
|
|
91
|
-
- headers
|
|
92
|
-
- data
|
|
93
|
-
- history_check
|
|
94
|
-
|
|
95
|
-
###
|
|
96
|
-
|
|
97
|
-
- delay
|
|
281
|
+
- **name**:调度的名称
|
|
282
|
+
- **client**:表示客户端信息。只有当所有五个元素都匹配时,调度才被认为是相同的
|
|
283
|
+
- **operation**:表示特定的调度目的,如流程
|
|
284
|
+
- **application**:客户端应用程序的名称
|
|
285
|
+
- **group**:域信息
|
|
286
|
+
- **key**:用于调度区分的单独密钥
|
|
287
|
+
- **type**:调度本身的资源类型
|
|
288
|
+
- **type**:主要类型包括`cron`、`now`、`date`、`delay`和`delay-recur`。详细描述请参阅"调度器类型"部分
|
|
289
|
+
- **schedule**:根据调度类型指定的字符串。详情请参阅"调度器类型"
|
|
290
|
+
- **timezone**:用于调度处理的时区字符串(如`Asia/Seoul`)
|
|
291
|
+
- **task**:包含调度触发时需要执行的必要任务信息
|
|
292
|
+
- **type**:指定任务类型,如`rest`、`kafka`或`redis`。对于`rest`,仅支持POST
|
|
293
|
+
- **connection**:任务执行的连接信息
|
|
294
|
+
- **host**:服务器连接信息
|
|
295
|
+
- **topic**:用于`kafka`和`redis`类型
|
|
296
|
+
- **headers**:对于`rest`类型可选
|
|
297
|
+
- **data**:指定任务执行期间要传递的数据
|
|
298
|
+
- **history_check**:在单独的数据库中保存调度注册、执行、删除和重新执行的历史记录
|
|
299
|
+
|
|
300
|
+
### 调度类型
|
|
301
|
+
|
|
302
|
+
- **delay**:等待特定时间(秒)后执行调度
|
|
98
303
|
|
|
99
304
|
```json
|
|
100
305
|
{
|
|
@@ -106,7 +311,7 @@
|
|
|
106
311
|
}
|
|
107
312
|
```
|
|
108
313
|
|
|
109
|
-
- delay-recur
|
|
314
|
+
- **delay-recur**:等待特定时间(秒)后重复执行调度
|
|
110
315
|
|
|
111
316
|
```json
|
|
112
317
|
{
|
|
@@ -118,10 +323,9 @@
|
|
|
118
323
|
}
|
|
119
324
|
```
|
|
120
325
|
|
|
121
|
-
- cron
|
|
122
|
-
|
|
123
|
-
-
|
|
124
|
-
- 초 단위 스케줄리을 실행하기 위해서는 6개 시간 요소가 필요하면, 첫번째 요소가 초를 지정합니다.
|
|
326
|
+
- **cron**:基于cron格式运行
|
|
327
|
+
- 使用基本的五元素格式
|
|
328
|
+
- 对于秒级调度,需要六元素格式,其中第一个元素指定秒
|
|
125
329
|
|
|
126
330
|
```json
|
|
127
331
|
{
|
|
@@ -133,7 +337,7 @@
|
|
|
133
337
|
}
|
|
134
338
|
```
|
|
135
339
|
|
|
136
|
-
- date
|
|
340
|
+
- **date**:指定特定日期和时间(ISO格式,`YYYY-MM-DDThh:mm:ss`)
|
|
137
341
|
|
|
138
342
|
```json
|
|
139
343
|
{
|
|
@@ -145,7 +349,8 @@
|
|
|
145
349
|
}
|
|
146
350
|
```
|
|
147
351
|
|
|
148
|
-
- now
|
|
352
|
+
- **now**:立即执行调度
|
|
353
|
+
|
|
149
354
|
```json
|
|
150
355
|
{
|
|
151
356
|
...
|
|
@@ -156,9 +361,9 @@
|
|
|
156
361
|
}
|
|
157
362
|
```
|
|
158
363
|
|
|
159
|
-
###
|
|
364
|
+
### 任务类型
|
|
160
365
|
|
|
161
|
-
- Rest
|
|
366
|
+
- **Rest**
|
|
162
367
|
|
|
163
368
|
```json
|
|
164
369
|
{
|
|
@@ -171,7 +376,7 @@
|
|
|
171
376
|
}
|
|
172
377
|
```
|
|
173
378
|
|
|
174
|
-
- Kafka & Redis
|
|
379
|
+
- **Kafka & Redis**
|
|
175
380
|
|
|
176
381
|
```json
|
|
177
382
|
{
|
|
@@ -183,3 +388,77 @@
|
|
|
183
388
|
}
|
|
184
389
|
}
|
|
185
390
|
```
|
|
391
|
+
|
|
392
|
+
## 🔧 高级配置
|
|
393
|
+
|
|
394
|
+
### 重试策略
|
|
395
|
+
|
|
396
|
+
#### ignore
|
|
397
|
+
|
|
398
|
+
- 无重试尝试
|
|
399
|
+
- 适用于非关键任务
|
|
400
|
+
|
|
401
|
+
#### retry
|
|
402
|
+
|
|
403
|
+
- 带指数退避的简单重试
|
|
404
|
+
- 适用于临时失败
|
|
405
|
+
|
|
406
|
+
#### retry_dlq
|
|
407
|
+
|
|
408
|
+
- 带死信队列回退的重试
|
|
409
|
+
- 最适合需要数据保护的关键任务
|
|
410
|
+
|
|
411
|
+
### 历史检查配置
|
|
412
|
+
|
|
413
|
+
#### true
|
|
414
|
+
|
|
415
|
+
- 防止重复执行
|
|
416
|
+
- 维护执行历史
|
|
417
|
+
- 适用于数据收集和报告
|
|
418
|
+
|
|
419
|
+
#### false
|
|
420
|
+
|
|
421
|
+
- 允许多次执行
|
|
422
|
+
- 无历史跟踪
|
|
423
|
+
- 适用于实时监控
|
|
424
|
+
|
|
425
|
+
### 时区考虑
|
|
426
|
+
|
|
427
|
+
- **全球部署**:支持多时区
|
|
428
|
+
- **营业时间**:基于当地营业时间的调度执行
|
|
429
|
+
- **DST处理**:自动夏令时调整
|
|
430
|
+
|
|
431
|
+
## 🚀 性能优化
|
|
432
|
+
|
|
433
|
+
### 最佳实践
|
|
434
|
+
|
|
435
|
+
1. **对短间隔使用delay-recur**:比cron更高效用于频繁任务
|
|
436
|
+
2. **对数据任务实现history_check**:防止重复数据处理
|
|
437
|
+
3. **配置适当的重试策略**:平衡可靠性和性能
|
|
438
|
+
4. **使用时区感知调度**:确保准确的执行时间
|
|
439
|
+
5. **监控DLQ**:定期检查和处理失败的任务
|
|
440
|
+
|
|
441
|
+
### 扩展考虑
|
|
442
|
+
|
|
443
|
+
- **水平扩展**:多个调度器实例可以同时运行
|
|
444
|
+
- **负载分布**:基于数据库的队列在实例间分布负载
|
|
445
|
+
- **故障转移支持**:实例宕机时自动故障转移
|
|
446
|
+
- **资源管理**:通过智能调度实现高效的资源利用
|
|
447
|
+
|
|
448
|
+
## 🔍 监控和故障排除
|
|
449
|
+
|
|
450
|
+
### 要监控的关键指标
|
|
451
|
+
|
|
452
|
+
- **执行成功率**:成功任务执行的百分比
|
|
453
|
+
- **重试频率**:每个任务的重试次数
|
|
454
|
+
- **DLQ大小**:死信队列中的任务数量
|
|
455
|
+
- **执行时间**:任务完成的平均时间
|
|
456
|
+
- **调度准确性**:与预期执行时间的偏差
|
|
457
|
+
|
|
458
|
+
### 常见问题和解决方案
|
|
459
|
+
|
|
460
|
+
1. **高重试率**:检查网络连接和目标服务可用性
|
|
461
|
+
2. **DLQ溢出**:审查失败的任务并修复根本原因
|
|
462
|
+
3. **执行遗漏**:验证时区设置和调度表达式
|
|
463
|
+
4. **性能问题**:考虑对频繁任务使用delay-recur
|
|
464
|
+
5. **重复执行**:对适当的任务启用history_check
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/scheduler",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.5",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@operato/graphql": "^9.0.0",
|
|
31
31
|
"@operato/shell": "^9.0.0",
|
|
32
|
-
"@things-factory/auth-base": "^9.0.
|
|
33
|
-
"@things-factory/scheduler-client": "^9.0.
|
|
34
|
-
"@things-factory/shell": "^9.0.
|
|
32
|
+
"@things-factory/auth-base": "^9.0.5",
|
|
33
|
+
"@things-factory/scheduler-client": "^9.0.5",
|
|
34
|
+
"@things-factory/shell": "^9.0.5"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "da760d5cf77e2495da74360b1cdc1f99f13bb65f"
|
|
37
37
|
}
|