summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/notifier/notifier.go23
-rw-r--r--internal/run.go3
2 files changed, 9 insertions, 17 deletions
diff --git a/internal/notifier/notifier.go b/internal/notifier/notifier.go
index 101303b..5fa1936 100644
--- a/internal/notifier/notifier.go
+++ b/internal/notifier/notifier.go
@@ -10,13 +10,7 @@ import (
"codeberg.org/snonux/gorum/internal/config"
)
-type Notifier struct{}
-
-func New() Notifier {
- return Notifier{}
-}
-
-func (notifier Notifier) Start(ctx context.Context, conf config.Config, scoreCh <-chan string) {
+func Start(ctx context.Context, conf config.Config, scoreCh <-chan string) {
changedCh := make(chan email, 1)
errorCh := make(chan email, 1)
@@ -29,20 +23,19 @@ func (notifier Notifier) Start(ctx context.Context, conf config.Config, scoreCh
}
go func() {
- go notifier.sendEmail(ctx, "change report", conf, changedCh)
- go notifier.sendEmail(ctx, "error report", conf, errorCh)
+ go sendEmail(ctx, "change report", conf, changedCh)
+ go sendEmail(ctx, "error report", conf, errorCh)
for scoresStr := range scoreCh {
- if err := notifier.persistToDisk(conf, scoresStr); err != nil {
+ if err := persistToDisk(conf, scoresStr); err != nil {
update(errorCh, email{"GORUM error", err.Error()})
}
update(changedCh, email{"GORUM changed", scoresStr})
}
}()
-
}
-func (notifier Notifier) sendEmail(ctx context.Context, what string, conf config.Config, ch <-chan email) {
+func sendEmail(ctx context.Context, what string, conf config.Config, ch <-chan email) {
throttleDuration := time.Duration(conf.MailThrottle)
for {
@@ -64,16 +57,16 @@ func (notifier Notifier) sendEmail(ctx context.Context, what string, conf config
}
}
-func (notifier Notifier) persistToDisk(conf config.Config, scoresStr string) error {
+func persistToDisk(conf config.Config, scoresStr string) error {
if _, err := os.Stat(conf.StateDir); os.IsNotExist(err) {
if err := os.MkdirAll(conf.StateDir, 0755); err != nil {
return err
}
}
- return notifier.writeFileViaTmp(fmt.Sprintf("%s/%s", conf.StateDir, conf.ScoreFile), scoresStr)
+ return writeFileViaTmp(fmt.Sprintf("%s/%s", conf.StateDir, conf.ScoreFile), scoresStr)
}
-func (Notifier) writeFileViaTmp(filePath, content string) error {
+func writeFileViaTmp(filePath, content string) error {
tmpFilePath := fmt.Sprintf("%s.tmp", filePath)
fd, err := os.Create(tmpFilePath)
diff --git a/internal/run.go b/internal/run.go
index d07ba28..82da984 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -33,9 +33,8 @@ func Run(ctx context.Context, configFile string, loopIntervalS int64) error {
log.Println("Starting everything up!")
quo := quorum.New(conf)
- notifier := notifier.New()
-
myVoteCh, scoreCh := quo.Start(ctx)
+
server.Start(ctx, conf, quo)
client.Start(ctx, conf, myVoteCh)
notifier.Start(ctx, conf, scoreCh)