log enabled dep
This commit is contained in:
parent
c5013c03ff
commit
b29e60b712
6 changed files with 39 additions and 21 deletions
|
|
@ -19,3 +19,4 @@ RABBIT_PORT=
|
||||||
RABBIT_USER=
|
RABBIT_USER=
|
||||||
RABBIT_PASS=
|
RABBIT_PASS=
|
||||||
RABBIT_VHOST=
|
RABBIT_VHOST=
|
||||||
|
RABBIT_LOGGING_ENABLED=
|
||||||
|
|
@ -33,6 +33,7 @@ type Rabbit struct {
|
||||||
User string
|
User string
|
||||||
Pass string
|
Pass string
|
||||||
Vhost string
|
Vhost string
|
||||||
|
LoggingEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() Config {
|
func NewConfig() Config {
|
||||||
|
|
@ -50,8 +51,10 @@ func NewConfig() Config {
|
||||||
},
|
},
|
||||||
|
|
||||||
TasksSource: TasksSource{
|
TasksSource: TasksSource{
|
||||||
Host: getEnv("TASK_SOURCE_HOST", "127.0.0.1"),
|
//Host: getEnv("TASK_SOURCE_HOST", "127.0.0.1"),
|
||||||
Port: getEnv("TASK_SOURCE_PORT", "61000"),
|
//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),
|
Timeout: getEnvSeconds("TASK_SOURCE_TIMEOUT_SECONDS", 60),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -61,6 +64,7 @@ func NewConfig() Config {
|
||||||
User: getEnv("RABBIT_USER", "taskProcessorDev"),
|
User: getEnv("RABBIT_USER", "taskProcessorDev"),
|
||||||
Pass: getEnv("RABBIT_PASS", "pass1234"),
|
Pass: getEnv("RABBIT_PASS", "pass1234"),
|
||||||
Vhost: getEnv("RABBIT_VHOST", "taskProcessorDevHost"),
|
Vhost: getEnv("RABBIT_VHOST", "taskProcessorDevHost"),
|
||||||
|
LoggingEnabled: getEnvBool("RABBIT_LOGGING_ENABLED", true),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,3 +50,14 @@ func getEnvPort(key string, fallback uint16) uint16 {
|
||||||
}
|
}
|
||||||
return fallback
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ func NewApp(ctx context.Context, cfg config.Config) *App {
|
||||||
Pass: cfg.Rabbit.Pass,
|
Pass: cfg.Rabbit.Pass,
|
||||||
Vhost: cfg.Rabbit.Vhost,
|
Vhost: cfg.Rabbit.Vhost,
|
||||||
},
|
},
|
||||||
|
LoggingEnabled: cfg.Rabbit.LoggingEnabled,
|
||||||
ChanLen: cfg.App.ProcChanLen,
|
ChanLen: cfg.App.ProcChanLen,
|
||||||
LoggerEnabled: false,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return &App{
|
return &App{
|
||||||
|
|
@ -53,11 +53,13 @@ func (app *App) Run(ctx context.Context) error {
|
||||||
defer mainLoop.Stop()
|
defer mainLoop.Stop()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
log.Info("Process tasks after start")
|
||||||
if err := app.processor.ProcessTasks(ctx); err != nil {
|
if err := app.processor.ProcessTasks(ctx); err != nil {
|
||||||
errChan <- err
|
errChan <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
for range mainLoop.C {
|
for range mainLoop.C {
|
||||||
|
log.WithField("period", app.config.App.CheckPeriod).Info("Repeated process tasks")
|
||||||
if err := app.processor.ProcessTasks(ctx); err != nil {
|
if err := app.processor.ProcessTasks(ctx); err != nil {
|
||||||
errChan <- err
|
errChan <- err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ type Deps struct {
|
||||||
TA taskAgent.TaskAgent
|
TA taskAgent.TaskAgent
|
||||||
Addr Addr
|
Addr Addr
|
||||||
ChanLen uint
|
ChanLen uint
|
||||||
LoggerEnabled bool
|
LoggingEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler(deps Deps) Processor {
|
func NewHandler(deps Deps) Processor {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func newService(deps Deps) *service {
|
||||||
s := &service{
|
s := &service{
|
||||||
taskAgent: deps.TA,
|
taskAgent: deps.TA,
|
||||||
brokerAddr: ba,
|
brokerAddr: ba,
|
||||||
rabbitLoggingEnabled: deps.LoggerEnabled,
|
rabbitLoggingEnabled: deps.LoggingEnabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
s.makeTaskPublishers(deps.Ctx, ba, deps.ChanLen)
|
s.makeTaskPublishers(deps.Ctx, ba, deps.ChanLen)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue