Skip to content

Commit

Permalink
Pass through the notification preference to creating the notification
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmcorvidae committed Sep 26, 2024
1 parent 049d1e3 commit b5cdab7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ iplant_groups:
const warningSentKey = "warningsent"
const oneDayWarningKey = "onedaywarning"

func sendNotif(ctx context.Context, j *Job, status, subject, msg, email_template string) error {
func sendNotif(ctx context.Context, j *Job, status, subject, msg string, email bool, email_template string) error {
var err error

// Don't send notification if things aren't configured correctly. It's
Expand Down Expand Up @@ -80,10 +80,12 @@ func sendNotif(ctx context.Context, j *Job, status, subject, msg, email_template
p.AnalysisStartDate = strconv.FormatInt(sdmillis, 10)
p.AnalysisResultsFolder = j.ResultFolder
p.RunDuration = durString
p.Email = user.Email
if email {
p.Email = user.Email
}
p.User = u

notif := NewNotification(u, subject, msg, true, email_template, p)
notif := NewNotification(u, subject, msg, email, email_template, p)

resp, err := notif.Send(ctx)
if err != nil {
Expand Down Expand Up @@ -143,7 +145,7 @@ func SendKillNotification(ctx context.Context, j *Job, killNotifKey string) erro
endtime.UTC().Format(time.UnixDate),
j.ResultFolder,
)
err = sendNotif(ctx, j, "Canceled", subject, msg, "analysis_status_change")
err = sendNotif(ctx, j, "Canceled", subject, msg, true, "analysis_status_change")
return err
}

Expand All @@ -167,7 +169,7 @@ func SendWarningNotification(ctx context.Context, j *Job) error {
j.ResultFolder,
)

return sendNotif(ctx, j, j.Status, subject, msg, "analysis_status_change")
return sendNotif(ctx, j, j.Status, subject, msg, true, "analysis_status_change")
}

func SendPeriodicNotification(ctx context.Context, j *Job) error {
Expand All @@ -186,7 +188,7 @@ func SendPeriodicNotification(ctx context.Context, j *Job) error {
durString,
)

return sendNotif(ctx, j, j.Status, subject, msg, "analysis_periodic_notification")
return sendNotif(ctx, j, j.Status, subject, msg, j.NotifyPeriodic, "analysis_periodic_notification")
}

func ensureNotifRecord(ctx context.Context, vicedb *VICEDatabaser, job Job) error {
Expand Down

0 comments on commit b5cdab7

Please sign in to comment.