Move starting the engine behind run cli argument.
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -12,46 +13,66 @@ import (
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
|
||||
log.Println("=== Bybit BTC/USDT Tick Ingest Engine ===")
|
||||
|
||||
// Load configuration
|
||||
cfg, err := LoadConfig("config.json")
|
||||
if err != nil {
|
||||
log.Fatalf("Config error: %v", err)
|
||||
}
|
||||
log.Printf("Config: symbol=%s, hot_retention=%dh, feature_retention=%dd",
|
||||
cfg.Symbol, cfg.HotRetentionHours, cfg.FeatureRetentionDays)
|
||||
|
||||
if len(os.Args) > 1 {
|
||||
if len(os.Args) < 2 {
|
||||
printUsage()
|
||||
return
|
||||
}
|
||||
|
||||
switch os.Args[1] {
|
||||
command := os.Args[1]
|
||||
|
||||
switch command {
|
||||
case "run":
|
||||
runEngine(cfg)
|
||||
|
||||
case "recover":
|
||||
log.Println("=== Starting Recovery Mode ===")
|
||||
sm, err := NewStorageManager(cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := sm.StartupRecovery(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Recovery completed.")
|
||||
return
|
||||
|
||||
case "maintain":
|
||||
log.Println("=== Starting Manual Maintenance ===")
|
||||
sm, err := NewStorageManager(cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
sm.RunHourlyMaintenance()
|
||||
|
||||
log.Println("Maintenance completed.")
|
||||
return
|
||||
|
||||
case "help":
|
||||
printUsage()
|
||||
|
||||
default:
|
||||
log.Printf("Unknown command: %s", command)
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
func printUsage() {
|
||||
fmt.Println("Usage: engine [command]")
|
||||
fmt.Println("\nCommands:")
|
||||
fmt.Println(" run Start the WebSocket ingestor and processing engine")
|
||||
fmt.Println(" recover Run startup recovery to migrate stale ticks")
|
||||
fmt.Println(" maintain Run a single maintenance cycle (cleanup/retention)")
|
||||
fmt.Println(" help Show this help message")
|
||||
}
|
||||
|
||||
func runEngine(cfg Config) {
|
||||
log.Println("=== Bybit BTC/USDT Tick Ingest Engine ===")
|
||||
log.Printf("Config: symbol=%s, hot_retention=%dh, feature_retention=%dd",
|
||||
cfg.Symbol, cfg.HotRetentionHours, cfg.FeatureRetentionDays)
|
||||
|
||||
// Initialize storage (creates dirs, databases, tables)
|
||||
sm, err := NewStorageManager(cfg)
|
||||
|
||||
Reference in New Issue
Block a user