Add seed and seed-slow targets to Makefile and Taskfile for generating sample telegrams. Enhance documentation with usage examples for continuous slow seeding and configuration options. This allows for easier testing and monitoring of message delivery in development environments.

This commit is contained in:
windyboy
2025-11-19 17:14:22 +08:00
parent 5ad86d6296
commit ee7cac95f0
4 changed files with 184 additions and 0 deletions
+57
View File
@@ -120,6 +120,63 @@ clean: ## Clean build artifacts and coverage files
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) coverage
.PHONY: seed
seed: ## Generate sample telegrams (publishes to Core NATS by default)
@GO_ENV=dev \
NATS_URL=$${CAATSM_NATS_URL:-nats://localhost:4222} \
SUBJECT=$${CAATSM_NATS_SUBJECT:-telegram.serial} \
COUNT=$${COUNT:-10} \
CATEGORY=$${CATEGORY:-mixed} \
STATUS=$${STATUS:-random} \
bash -c ' \
set -euo pipefail; \
cmd=(go run ./cmd/seed-telegrams); \
if [ -n "$$NATS_URL" ]; then \
cmd+=("--nats-url" "$$NATS_URL"); \
fi; \
cmd+=("--subject" "$$SUBJECT" "--count" "$$COUNT" "--category" "$$CATEGORY" "--status" "$$STATUS"); \
exec "$${cmd[@]}" \
'
.PHONY: seed-slow
seed-slow: ## Continuously send telegrams slowly (until Ctrl-C). Uses JetStream by default. Configurable interval.
@echo "Starting slow continuous telegram seeding..."
@echo " Mode: $${MODE:-interval}"
@echo " Interval: $${INTERVAL_MIN:-2s} - $${INTERVAL_MAX:-5s}"
@echo " Category: $${CATEGORY:-mixed}"
@echo " Status: $${STATUS:-random}"
@echo " Press Ctrl-C to stop"
@echo ""
@GO_ENV=dev \
NATS_URL=$${CAATSM_NATS_URL:-nats://localhost:4222} \
SUBJECT=$${CAATSM_NATS_SUBJECT:-telegram.serial} \
CATEGORY=$${CATEGORY:-mixed} \
STATUS=$${STATUS:-random} \
MODE=$${MODE:-interval} \
INTERVAL_MIN=$${INTERVAL_MIN:-2s} \
INTERVAL_MAX=$${INTERVAL_MAX:-5s} \
USE_JS=$${USE_JS:-true} \
JS_STREAM=$${JS_STREAM:-TELEGRAM} \
JS_SUBJECT=$${JS_SUBJECT:-} \
bash -c ' \
set -euo pipefail; \
cmd=(go run ./cmd/seed-telegrams); \
if [ -n "$$NATS_URL" ]; then \
cmd+=("--nats-url" "$$NATS_URL"); \
fi; \
if [ "$$USE_JS" = "true" ]; then \
cmd+=("--jetstream"); \
if [ -n "$$JS_STREAM" ]; then \
cmd+=("--stream" "$$JS_STREAM"); \
fi; \
if [ -n "$$JS_SUBJECT" ]; then \
cmd+=("--js-subject" "$$JS_SUBJECT"); \
fi; \
fi; \
cmd+=("--subject" "$$SUBJECT" "--count" "0" "--category" "$$CATEGORY" "--status" "$$STATUS" "--mode" "$$MODE" "--interval-min" "$$INTERVAL_MIN" "--interval-max" "$$INTERVAL_MAX"); \
exec "$${cmd[@]}" \
'
.PHONY: help
help: ## Show this help
@printf "Makefile targets:\n"
+25
View File
@@ -918,6 +918,31 @@ go run ./cmd/seed-telegrams \
--category=FPL
```
#### 5. 持续缓慢发送(直到 Ctrl-C)
```bash
# 使用 Makefile/Taskfile 任务(推荐)
make seed-slow
# 或
task seed-slow
# 自定义间隔时间
make seed-slow INTERVAL_MIN=3s INTERVAL_MAX=8s
# 直接使用命令行
go run ./cmd/seed-telegrams \
--nats-url nats://localhost:4222 \
--jetstream \
--stream TELEGRAM \
--js-subject telegram.serial \
--mode interval \
--interval-min 2s \
--interval-max 5s \
--count 0
```
**注意**:设置 `--count 0` 会持续发送直到手动停止(Ctrl-C)。这对于长时间测试和监控系统行为非常有用。
该工具专门为开发与测试设计,不影响生产服务逻辑,推荐在本地或测试环境配合解析与存储流水线一起使用,用于回归测试、吞吐量观察和错误场景演练。
**Parsed Fields:**
+49
View File
@@ -290,6 +290,55 @@ tasks:
exec "${cmd[@]}"
'
seed-slow:
desc: Continuously send telegrams slowly (until Ctrl-C). Uses JetStream by default. Configurable interval.
cmds:
- |
GO_ENV=dev \
NATS_URL=${CAATSM_NATS_URL:-nats://localhost:4222} \
SUBJECT=${CAATSM_NATS_SUBJECT:-telegram.serial} \
CATEGORY={{.CATEGORY | default "mixed"}} \
STATUS={{.STATUS | default "random"}} \
MODE={{.MODE | default "interval"}} \
INTERVAL_MIN={{.INTERVAL_MIN | default "2s"}} \
INTERVAL_MAX={{.INTERVAL_MAX | default "5s"}} \
USE_JS={{.USE_JS | default "true"}} \
JS_STREAM={{.JS_STREAM | default "TELEGRAM"}} \
JS_SUBJECT={{.JS_SUBJECT | default ""}} \
bash -c '
set -euo pipefail
echo "Starting slow continuous telegram seeding..."
echo " Mode: $MODE"
echo " Interval: $INTERVAL_MIN - $INTERVAL_MAX"
echo " Category: $CATEGORY"
echo " Status: $STATUS"
echo " Press Ctrl-C to stop"
echo ""
cmd=(go run ./cmd/seed-telegrams)
if [ -n "$NATS_URL" ]; then
cmd+=("--nats-url" "$NATS_URL")
fi
if [ "$USE_JS" = "true" ]; then
cmd+=("--jetstream")
if [ -n "$JS_STREAM" ]; then
cmd+=("--stream" "$JS_STREAM")
fi
if [ -n "$JS_SUBJECT" ]; then
cmd+=("--js-subject" "$JS_SUBJECT")
fi
fi
cmd+=(
--subject "$SUBJECT"
--count 0
--category "$CATEGORY"
--status "$STATUS"
--mode "$MODE"
--interval-min "$INTERVAL_MIN"
--interval-max "$INTERVAL_MAX"
)
exec "${cmd[@]}"
'
help:
desc: Show this help message
cmds:
+53
View File
@@ -94,6 +94,56 @@ GO_ENV=dev go run ./cmd/seed-telegrams \
--status random
```
### Using Makefile/Taskfile Tasks
For convenience, you can use the provided tasks:
```bash
# Quick seed (10 messages, Core NATS)
make seed
# or
task seed
# Continuous slow seeding (until Ctrl-C, JetStream by default)
make seed-slow
# or
task seed-slow
# Customize slow seeding
make seed-slow INTERVAL_MIN=3s INTERVAL_MAX=8s CATEGORY=ARR
task seed-slow INTERVAL_MIN=1s INTERVAL_MAX=2s STATUS=parsed
```
### Continuous Slow Seeding
For long-running tests and monitoring, use the `seed-slow` task to continuously send messages at a configurable interval until you press Ctrl-C:
```bash
# Default: 2-5 second intervals, JetStream mode
make seed-slow
# Custom interval and category
make seed-slow INTERVAL_MIN=5s INTERVAL_MAX=10s CATEGORY=DEP
# Use Core NATS instead of JetStream
make seed-slow USE_JS=false INTERVAL_MIN=1s INTERVAL_MAX=3s
```
This is equivalent to running:
```bash
go run ./cmd/seed-telegrams \
--nats-url nats://localhost:4222 \
--jetstream \
--stream TELEGRAM \
--js-subject telegram.serial \
--mode interval \
--interval-min 2s \
--interval-max 5s \
--count 0
```
Setting `--count 0` makes it run indefinitely until interrupted.
### Common Options
- `--postgres-url`: Insert rows into `aviation.telegrams_raw` (omit to skip DB writes)
@@ -104,6 +154,9 @@ GO_ENV=dev go run ./cmd/seed-telegrams \
- `--jetstream`: Enable JetStream publishing (requires `--stream` and `--js-subject`)
- `--stream`: JetStream stream name (default: `TELEGRAM`)
- `--js-subject`: Subject within the JetStream stream
- `--mode`: Seed mode (`burst|interval|mixed`)
- `--interval-min` / `--interval-max`: Time interval between messages in interval/mixed modes
- `--count`: Number of messages to send (0 = infinite, until Ctrl-C)
### Inspecting Messages