Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

36: add kill signal to pause interval loop #42

Merged
merged 1 commit into from
Dec 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions content/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func (s *Scheduler) Run() error {
if err != nil {
return err
}
go func() {
for {
stop := <-sigchnl
s.Stop(stop, nil) // passing nil because there is no media to stop.
}
}()
// pause the loop
log.WithField("pause interval", s.Content.CheckInterval).Info("loop paused, will resume after pause interval")
time.Sleep(interval)
Expand Down Expand Up @@ -131,13 +137,19 @@ func (s *Scheduler) Shuffle() error {
func (s *Scheduler) Stop(signal os.Signal, media Media) {
if signal == syscall.SIGTERM {
log.Info("Got kill signal. ")
media.Stop()
if media != nil {
media.Stop()
}
log.Info("Program will terminate now.")
os.Exit(0)
} else if signal == syscall.SIGINT {
media.Stop()
if media != nil {
media.Stop()
}
log.Info("Got CTRL+C signal")
media.Stop()
if media != nil {
media.Stop()
}
fmt.Println("Closing.")
os.Exit(0)
}
Expand Down