56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"flag"
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
"os/signal"
|
||
|
|
"syscall"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"apps/backend/internal/config"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/conf"
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Independent worker binary (A-03). M0 stub: config load + heartbeat log only.
|
||
|
|
// Outbox/job runners land in M2/M4 (T133/T169).
|
||
|
|
func main() {
|
||
|
|
configFile := flag.String("f", "etc/gateway.yaml", "config file")
|
||
|
|
flag.Parse()
|
||
|
|
|
||
|
|
var c config.Config
|
||
|
|
conf.MustLoad(*configFile, &c)
|
||
|
|
c.ApplyEnv()
|
||
|
|
|
||
|
|
workerID := c.Worker.ID
|
||
|
|
if workerID == "" {
|
||
|
|
workerID = "worker-1"
|
||
|
|
}
|
||
|
|
interval := time.Duration(c.Worker.PollIntervalMs) * time.Millisecond
|
||
|
|
if interval <= 0 {
|
||
|
|
interval = 2 * time.Second
|
||
|
|
}
|
||
|
|
|
||
|
|
logx.Infof("haixun worker stub started id=%s interval=%s (no publish yet)", workerID, interval)
|
||
|
|
fmt.Printf("worker stub running id=%s (Ctrl+C to stop)\n", workerID)
|
||
|
|
|
||
|
|
sig := make(chan os.Signal, 1)
|
||
|
|
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||
|
|
|
||
|
|
tick := time.NewTicker(interval)
|
||
|
|
defer tick.Stop()
|
||
|
|
|
||
|
|
for {
|
||
|
|
select {
|
||
|
|
case <-sig:
|
||
|
|
logx.Infof("worker %s shutting down", workerID)
|
||
|
|
return
|
||
|
|
case t := <-tick.C:
|
||
|
|
// Health heartbeat only — no job/outbox processing in M0.
|
||
|
|
logx.Infof("worker %s heartbeat at %s", workerID, t.UTC().Format(time.RFC3339))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|