package main

import (
	"context"
	"flag"
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"haixun-backend/internal/config"
	"haixun-backend/internal/svc"

	"github.com/zeromicro/go-zero/core/conf"
)

var configFile = flag.String("f", "etc/gateway.worker.yaml", "config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)
	if !c.JobWorker.Enabled {
		fmt.Fprintln(os.Stderr, "[worker] JobWorker.Enabled must be true")
		os.Exit(1)
	}

	sc := svc.NewServiceContext(c)
	defer sc.Close(context.Background())

	fmt.Printf(
		"[worker] started type=%s (scheduler=%v reaper=%v)\n",
		c.JobWorker.WorkerType,
		c.JobScheduler.Enabled,
		c.JobReaper.Enabled,
	)

	ch := make(chan os.Signal, 1)
	signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
	<-ch
	fmt.Println("[worker] shutting down")
}