summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-11-13 22:46:33 +0200
committerPaul Buetow <paul@buetow.org>2023-11-13 22:46:33 +0200
commit1ec99f2476257aef733bada29bffe3e8b83f7b6b (patch)
tree75b456308775917bbfc62cdbc5d9bd9a90c1d974
parent4cfb4b1dd2e9efe399318f13abbe298b0a9904a3 (diff)
fix duration - minor refactor
-rw-r--r--internal/notifier/notifier.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/internal/notifier/notifier.go b/internal/notifier/notifier.go
index 5fa1936..1f228f9 100644
--- a/internal/notifier/notifier.go
+++ b/internal/notifier/notifier.go
@@ -11,21 +11,21 @@ import (
)
func Start(ctx context.Context, conf config.Config, scoreCh <-chan string) {
+ log.Println("notifier: Starting")
+
changedCh := make(chan email, 1)
errorCh := make(chan email, 1)
update := func(ch chan email, email email) {
// Replace (update) current element in the channel.
- if cap(ch) == len(ch) {
- <-ch
+ select {
+ case <-ch:
+ default:
}
ch <- email
}
go func() {
- go sendEmail(ctx, "change report", conf, changedCh)
- go sendEmail(ctx, "error report", conf, errorCh)
-
for scoresStr := range scoreCh {
if err := persistToDisk(conf, scoresStr); err != nil {
update(errorCh, email{"GORUM error", err.Error()})
@@ -33,10 +33,13 @@ func Start(ctx context.Context, conf config.Config, scoreCh <-chan string) {
update(changedCh, email{"GORUM changed", scoresStr})
}
}()
+
+ go sendEmail(ctx, "change report", conf, changedCh)
+ go sendEmail(ctx, "error report", conf, errorCh)
}
func sendEmail(ctx context.Context, what string, conf config.Config, ch <-chan email) {
- throttleDuration := time.Duration(conf.MailThrottle)
+ throttleDuration := time.Duration(conf.MailThrottle) * time.Second
for {
select {
@@ -50,7 +53,7 @@ func sendEmail(ctx context.Context, what string, conf config.Config, ch <-chan e
select {
case <-time.After(throttleDuration):
- log.Println("notifier:", what, "slept some seconds", throttleDuration)
+ log.Println("notifier:", what, "slept some time", throttleDuration)
case <-ctx.Done():
return
}