fix(postgres): task alert body carries the truncated task title, not a restated title
This commit is contained in:
1 parent
343da517bf
commit
bde67cc438
1 file changed
+11
-2
@@ -57,7 +57,7 @@ func syncTaskAlerts(ctx context.Context, q *postgresdb.Queries, p postgresdb.Ins
|
||||
name := fmt.Sprintf("Task #%d", p.TaskID)
|
||||
title := name
|
||||
if info.Title != "" {
|
||||
title = info.Title
|
||||
title = truncate(info.Title, 80)
|
||||
}
|
||||
key := func(kind string) alert.Key {
|
||||
return alert.Key{Org: org.OrgID(info.OrgID), Kind: kind, Subject: subject}
|
||||
@@ -83,9 +83,18 @@ func syncTaskAlerts(ctx context.Context, q *postgresdb.Queries, p postgresdb.Ins
|
||||
if failed(p.ToStatus, info.ParkClass) {
|
||||
_, err := raiseAlert(ctx, q, alert.Input{
|
||||
Key: key(alert.KindTaskFailed), Severity: alert.SeverityWarning,
|
||||
Title: title, Body: name + " failed and will not run again until you retry it.", Link: link,
|
||||
Title: title, Body: name + " failed.", Link: link,
|
||||
})
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// truncate shortens s to at most n runes, marking the cut with an ellipsis.
|
||||
func truncate(s string, n int) string {
|
||||
r := []rune(s)
|
||||
if len(r) <= n {
|
||||
return s
|
||||
}
|
||||
return string(r[:n-1]) + "…"
|
||||
}
|
||||
Reference in new issue
Block a user