Skip to content

Commit 3afb51d

Browse files
committed
✨ notify mx if there's an error
1 parent d04f5e5 commit 3afb51d

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

internal/datacontroller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ func (d *DataController) checkAndDo(ctx context.Context, taskData *persistence.T
121121
log.Info("worker : time elapsed, get data...")
122122

123123
if err := d.getAndSaveIssues(ctx); err != nil {
124+
d.matrixClient.NotifyError(ctx, err)
125+
// Updating task data to avoid short fail loop
126+
if err = d.queries.UpdateTimeTaskData(ctx,
127+
sql.NullTime{Time: time.Now(), Valid: true}); err != nil {
128+
log.Error("Error updating task data", "error", err)
129+
}
130+
124131
return
125132
}
126133
}

internal/matrixNotif.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ func CreateMatrixClient(ctx context.Context, settingsService *SettingsService) *
4949
}
5050

5151
func (c *MatrixClient) Notify(ctx context.Context, issue *HelpWantedIssue) {
52+
if c == nil {
53+
log.Warn("Matrix not configured")
54+
55+
return
56+
}
57+
5258
message := fmt.Sprintf("Help wanted for new issue :\n%s\n%s", issue.Title, issue.Url)
5359

5460
content := event.MessageEventContent{
@@ -64,6 +70,12 @@ func (c *MatrixClient) Notify(ctx context.Context, issue *HelpWantedIssue) {
6470
}
6571

6672
func (c *MatrixClient) NotifySeveralNewIssues(ctx context.Context) {
73+
if c == nil {
74+
log.Warn("Matrix not configured")
75+
76+
return
77+
}
78+
6779
message := "Help wanted for several new issues. Could be worth checking Help-the-stars interface ⭐"
6880

6981
content := event.MessageEventContent{
@@ -77,3 +89,29 @@ func (c *MatrixClient) NotifySeveralNewIssues(ctx context.Context) {
7789
log.Error(err)
7890
}
7991
}
92+
93+
func (c *MatrixClient) NotifyError(ctx context.Context, err error) {
94+
if c == nil {
95+
log.Warn("Matrix not configured")
96+
97+
return
98+
}
99+
100+
formattedMessage := fmt.Sprintf(`⚠️ Oups an error occurred:
101+
\n<blockquote>%s</blockquote>\n
102+
It will be retried next iteration...`, err)
103+
message := fmt.Sprintf("⚠️ Oups an error occurred: \n%s\nIt will be retried next iteration...", err)
104+
105+
content := event.MessageEventContent{
106+
Format: event.FormatHTML,
107+
FormattedBody: formattedMessage,
108+
MsgType: event.MsgText,
109+
Body: message,
110+
}
111+
112+
_, err = c.client.SendMessageEvent(ctx,
113+
id.RoomID(c.MatrixRoomID), event.EventMessage, content)
114+
if err != nil {
115+
log.Error(err)
116+
}
117+
}

0 commit comments

Comments
 (0)