ms-runner/main.go
Vyacheslav1557 1fa11f66e3 feat:
2024-11-01 23:22:43 +05:00

50 lines
1 KiB
Go

package main
import (
"fmt"
"git.sch9.ru/new_gate/ms-runner/config"
runnerPubSub "git.sch9.ru/new_gate/ms-runner/internal/runner/delivery/rabbitmq"
runnerUseCase "git.sch9.ru/new_gate/ms-runner/internal/runner/usecase"
"git.sch9.ru/new_gate/ms-runner/pkg/external/rabbitmq"
"github.com/ilyakaznacheev/cleanenv"
"os"
"os/signal"
"syscall"
)
func main() {
var cfg config.Config
err := cleanenv.ReadConfig(".env", &cfg)
if err != nil {
panic(fmt.Sprintf("error reading config: %s", err.Error()))
}
conn, err := rabbitmq.NewRabbitClient(cfg.RabbitDSN)
if err != nil {
panic(err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
panic(err)
}
defer ch.Close()
err = ch.Qos(
1,
0,
true,
)
if err != nil {
panic(err)
}
runnerUC := runnerUseCase.NewRunnerUseCase(10)
runnerPubSub.NewRunnerBuilderProducer(ch, runnerUC)
runnerPubSub.NewRunnerBuilderConsumer(ch, runnerUC, cfg.TQueueName, cfg.InstanceName)
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT)
<-stop
}