diff --git a/config.env b/config.env index 42f4f76..a5a9766 100644 --- a/config.env +++ b/config.env @@ -18,4 +18,5 @@ RABBIT_HOST= RABBIT_PORT= RABBIT_USER= RABBIT_PASS= -RABBIT_VHOST= \ No newline at end of file +RABBIT_VHOST= +RABBIT_LOGGING_ENABLED= \ No newline at end of file diff --git a/config/config.go b/config/config.go index d0528ba..00e5411 100644 --- a/config/config.go +++ b/config/config.go @@ -28,11 +28,12 @@ type TasksSource struct { } type Rabbit struct { - Host string - Port uint16 - User string - Pass string - Vhost string + Host string + Port uint16 + User string + Pass string + Vhost string + LoggingEnabled bool } func NewConfig() Config { @@ -50,17 +51,20 @@ func NewConfig() Config { }, TasksSource: TasksSource{ - Host: getEnv("TASK_SOURCE_HOST", "127.0.0.1"), - Port: getEnv("TASK_SOURCE_PORT", "61000"), + //Host: getEnv("TASK_SOURCE_HOST", "127.0.0.1"), + //Port: getEnv("TASK_SOURCE_PORT", "61000"), + Host: getEnv("TASK_SOURCE_HOST", "10.0.0.1"), + Port: getEnv("TASK_SOURCE_PORT", "9099"), Timeout: getEnvSeconds("TASK_SOURCE_TIMEOUT_SECONDS", 60), }, Rabbit: Rabbit{ - Host: getEnv("RABBIT_HOST", "10.0.0.4"), - Port: getEnvPort("RABBIT_PORT", 5672), - User: getEnv("RABBIT_USER", "taskProcessorDev"), - Pass: getEnv("RABBIT_PASS", "pass1234"), - Vhost: getEnv("RABBIT_VHOST", "taskProcessorDevHost"), + Host: getEnv("RABBIT_HOST", "10.0.0.4"), + Port: getEnvPort("RABBIT_PORT", 5672), + User: getEnv("RABBIT_USER", "taskProcessorDev"), + Pass: getEnv("RABBIT_PASS", "pass1234"), + Vhost: getEnv("RABBIT_VHOST", "taskProcessorDevHost"), + LoggingEnabled: getEnvBool("RABBIT_LOGGING_ENABLED", true), }, } } diff --git a/config/helper.go b/config/helper.go index 1771dbe..5ff6a49 100644 --- a/config/helper.go +++ b/config/helper.go @@ -50,3 +50,14 @@ func getEnvPort(key string, fallback uint16) uint16 { } return fallback } + +func getEnvBool(key string, fallback bool) bool { + if value, ok := os.LookupEnv(key); ok { + val, err := strconv.ParseBool(value) + if err != nil { + return fallback + } + return val + } + return fallback +} diff --git a/internal/app/handler.go b/internal/app/handler.go index 5f050f6..f895073 100644 --- a/internal/app/handler.go +++ b/internal/app/handler.go @@ -33,8 +33,8 @@ func NewApp(ctx context.Context, cfg config.Config) *App { Pass: cfg.Rabbit.Pass, Vhost: cfg.Rabbit.Vhost, }, - ChanLen: cfg.App.ProcChanLen, - LoggerEnabled: false, + LoggingEnabled: cfg.Rabbit.LoggingEnabled, + ChanLen: cfg.App.ProcChanLen, }) return &App{ @@ -53,11 +53,13 @@ func (app *App) Run(ctx context.Context) error { defer mainLoop.Stop() go func() { + log.Info("Process tasks after start") if err := app.processor.ProcessTasks(ctx); err != nil { errChan <- err } for range mainLoop.C { + log.WithField("period", app.config.App.CheckPeriod).Info("Repeated process tasks") if err := app.processor.ProcessTasks(ctx); err != nil { errChan <- err } diff --git a/internal/processor/handler.go b/internal/processor/handler.go index 3252672..164cb44 100644 --- a/internal/processor/handler.go +++ b/internal/processor/handler.go @@ -20,11 +20,11 @@ type Addr struct { } type Deps struct { - Ctx context.Context - TA taskAgent.TaskAgent - Addr Addr - ChanLen uint - LoggerEnabled bool + Ctx context.Context + TA taskAgent.TaskAgent + Addr Addr + ChanLen uint + LoggingEnabled bool } func NewHandler(deps Deps) Processor { diff --git a/internal/processor/service.go b/internal/processor/service.go index 4544487..1cebf06 100644 --- a/internal/processor/service.go +++ b/internal/processor/service.go @@ -30,7 +30,7 @@ func newService(deps Deps) *service { s := &service{ taskAgent: deps.TA, brokerAddr: ba, - rabbitLoggingEnabled: deps.LoggerEnabled, + rabbitLoggingEnabled: deps.LoggingEnabled, } s.makeTaskPublishers(deps.Ctx, ba, deps.ChanLen)