Skip to content

Commit

Permalink
start sending successful notifications, fix telegram messages formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal authored and umputun committed May 24, 2024
1 parent 2b0ae5a commit 968c7f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (s *Service) Send(ctx context.Context, subj, text string) error {
err = errors.Join(err, notify.Send(ctx, s.destinations, destination, text))
}
for _, telegramDestination := range s.telegramDestinations {
destination := fmt.Sprintf("telegram:%s?type=HTML", telegramDestination)
destination := fmt.Sprintf("telegram:%s?parseMode=HTML", telegramDestination)
err = errors.Join(err, notify.Send(ctx, s.destinations, destination, notify.TelegramSupportedHTML(text)))
}
for _, webhookURL := range s.webhookURLs {
Expand Down Expand Up @@ -272,7 +272,7 @@ var (
<ul>
<li>Command: <span class="bold">{{.Command}}</span></li>
<li>Spec: <span class="bold">{{.Spec}}</span></li>
</ul>>
</ul>
</body>
</html>
`
Expand Down
17 changes: 11 additions & 6 deletions app/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,17 @@ func (s *Scheduler) jobFunc(r crontab.JobSpec, sched Schedule) cron.FuncJob {
return fmt.Errorf("failed to initiate resumer for %+v: %w", cmd, rerr)
}

if err = s.executeCommand(cmd, s.Stdout); err != nil {
ctxTimeout, cancel := context.WithTimeout(context.Background(), s.NotifyTimeout)
defer cancel()
if e := s.notify(ctxTimeout, r, err.Error()); e != nil {
return fmt.Errorf("failed to notify: %w", err)
}
err = s.executeCommand(cmd, s.Stdout)
ctxTimeout, cancel := context.WithTimeout(context.Background(), s.NotifyTimeout)
defer cancel()
var errMsg string
if err != nil {
errMsg = err.Error()
}
if e := s.notify(ctxTimeout, r, errMsg); e != nil {
return fmt.Errorf("failed to notify: %w", err)
}
if err != nil {
return err
}

Expand Down

0 comments on commit 968c7f3

Please sign in to comment.