Add ability to control eventbus scheduler via options
This commit is contained in:
+16
-10
@@ -98,15 +98,19 @@ func (app *CortezaApp) Setup() (err error) {
|
||||
|
||||
monitor.Setup(app.Log, app.Opt.Monitor)
|
||||
|
||||
scheduler.Setup(app.Log, eventbus.Service(), 0)
|
||||
scheduler.Service().OnTick(
|
||||
sysEvent.SystemOnInterval(),
|
||||
sysEvent.SystemOnTimestamp(),
|
||||
cmpEvent.ComposeOnInterval(),
|
||||
cmpEvent.ComposeOnTimestamp(),
|
||||
msgEvent.MessagingOnInterval(),
|
||||
msgEvent.MessagingOnTimestamp(),
|
||||
)
|
||||
if app.Opt.Eventbus.SchedulerEnabled {
|
||||
scheduler.Setup(app.Log, eventbus.Service(), app.Opt.Eventbus.SchedulerInterval)
|
||||
scheduler.Service().OnTick(
|
||||
sysEvent.SystemOnInterval(),
|
||||
sysEvent.SystemOnTimestamp(),
|
||||
cmpEvent.ComposeOnInterval(),
|
||||
cmpEvent.ComposeOnTimestamp(),
|
||||
msgEvent.MessagingOnInterval(),
|
||||
msgEvent.MessagingOnTimestamp(),
|
||||
)
|
||||
} else {
|
||||
app.Log.Debug("eventbus scheduler disabled (EVENTBUS_SCHEDULER_ENABLED=false)")
|
||||
}
|
||||
|
||||
if err = corredor.Setup(app.Log, app.Opt.Corredor); err != nil {
|
||||
return err
|
||||
@@ -294,7 +298,9 @@ func (app *CortezaApp) Activate(ctx context.Context) (err error) {
|
||||
defer sentry.Recover()
|
||||
|
||||
// Start scheduler
|
||||
scheduler.Service().Start(ctx)
|
||||
if app.Opt.Eventbus.SchedulerEnabled {
|
||||
scheduler.Service().Start(ctx)
|
||||
}
|
||||
|
||||
// Load corredor scripts & init watcher (script reloader)
|
||||
corredor.Service().Load(ctx)
|
||||
|
||||
@@ -21,6 +21,7 @@ type (
|
||||
WaitFor options.WaitForOpt
|
||||
HTTPServer options.HTTPServerOpt
|
||||
Websocket options.WebsocketOpt
|
||||
Eventbus options.EventbusOpt
|
||||
}
|
||||
)
|
||||
|
||||
@@ -42,5 +43,6 @@ func NewOptions() *Options {
|
||||
WaitFor: *options.WaitFor(),
|
||||
HTTPServer: *options.HTTPServer(),
|
||||
Websocket: *options.Websocket(),
|
||||
Eventbus: *options.Eventbus(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/eventbus.yaml
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
EventbusOpt struct {
|
||||
SchedulerEnabled bool `env:"EVENTBUS_SCHEDULER_ENABLED"`
|
||||
SchedulerInterval time.Duration `env:"EVENTBUS_SCHEDULER_INTERVAL"`
|
||||
}
|
||||
)
|
||||
|
||||
// Eventbus initializes and returns a EventbusOpt with default values
|
||||
func Eventbus() (o *EventbusOpt) {
|
||||
o = &EventbusOpt{
|
||||
SchedulerEnabled: true,
|
||||
SchedulerInterval: time.Minute,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
// Function that allows access to custom logic inside the parent function.
|
||||
// The custom logic in the other file should be like:
|
||||
// func (o *Eventbus) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
name: eventbus
|
||||
|
||||
imports:
|
||||
- time
|
||||
|
||||
props:
|
||||
- name: schedulerEnabled
|
||||
type: bool
|
||||
default: true
|
||||
|
||||
- name: schedulerInterval
|
||||
type: time.Duration
|
||||
default: time.Minute
|
||||
Reference in New Issue
Block a user