diff --git a/app/boot_levels.go b/app/boot_levels.go index c6f13f5ed..7b8315cff 100644 --- a/app/boot_levels.go +++ b/app/boot_levels.go @@ -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) diff --git a/app/options.go b/app/options.go index e957b7238..471324659 100644 --- a/app/options.go +++ b/app/options.go @@ -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(), } } diff --git a/pkg/options/eventbus.gen.go b/pkg/options/eventbus.gen.go new file mode 100644 index 000000000..b67ce5f49 --- /dev/null +++ b/pkg/options/eventbus.gen.go @@ -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 +} diff --git a/pkg/options/eventbus.yaml b/pkg/options/eventbus.yaml new file mode 100644 index 000000000..b2feb33bb --- /dev/null +++ b/pkg/options/eventbus.yaml @@ -0,0 +1,13 @@ +name: eventbus + +imports: + - time + +props: + - name: schedulerEnabled + type: bool + default: true + + - name: schedulerInterval + type: time.Duration + default: time.Minute