Skip to content

Commit

Permalink
Fixes issues with never ending looping inside rotondo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Leduc-Hamel committed Apr 9, 2021
1 parent b44280d commit 134ba6e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion services/rotondo/pkg/apps/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func NewScheduler(cfg *config.Config) *Scheduler {
}

func (s *Scheduler) Run(ctx context.Context) error {
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Running production every hour")

ctx, cancelFun := context.WithCancel(ctx)
defer cancelFun()
_, err := s.scheduler.Every(1).Hour().Do(s.rougecombien(ctx))
Expand All @@ -37,46 +39,60 @@ func (s *Scheduler) Run(ctx context.Context) error {
}

func (s *Scheduler) RunDevelopment(ctx context.Context) error {
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Running development every minute")

ctx, cancelFun := context.WithCancel(ctx)
defer cancelFun()

_, err := s.scheduler.Every(1).Minute().Do(s.rougecombienDevelopment(ctx))

if err != nil {
s.cfg.Logger().Error().Str("service", "rotondo").Err(err)
return err
}

s.loop(ctx)

s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Done development every minute")

return nil
}

func (s *Scheduler) rougecombien(ctx context.Context) func() {
return func() {
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Running rougecombien production")
app := rougecombien.NewRougecombien(s.cfg)
err := app.Run(ctx)
if err != nil {
s.cfg.Logger().Error().Str("service", "rotondo").Err(err)
panic(err)
}
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Done rougecombien production")
}
}

func (s *Scheduler) rougecombienDevelopment(ctx context.Context) func() {
return func() {
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Running rougecombien development")
app := rougecombien.NewRougecombien(s.cfg)
err := app.RunDevelopment(ctx)
if err != nil {
s.cfg.Logger().Error().Str("service", "rotondo").Err(err)
panic(err)
}
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Done rougecombien development")
}
}

func (s *Scheduler) loop(ctx context.Context) {
s.scheduler.StartAsync()
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Running loop")

s.scheduler.StartBlocking()

for {
select {
case <-ctx.Done():
s.cfg.Logger().Debug().Str("service", "rotondo").Msg("Stopping scheduler")
s.scheduler.Stop()
}
}
Expand Down

0 comments on commit 134ba6e

Please sign in to comment.