Skip to content

Modern Docker Management, Designed for Everyone

fix: send prune and update notifications after context cancel (#4501)

Kyle Mendella41e677e7b75
diff --git a/backend/internal/notification/children/templates/service.go b/backend/internal/notification/children/templates/service.go
index aaff2c818..bbdc0da64 100644
--- a/backend/internal/notification/children/templates/service.go
+++ b/backend/internal/notification/children/templates/service.go
@@ -8,6 +8,7 @@ import (
"maps"
"slices"
"sort"
+ "strings"
"time"
"github.com/getarcaneapp/arcane/types/v2/imageupdate"
@@ -159,14 +160,18 @@ func (s *Service) PruneReport(environmentName string, result *system.PruneAllRes
return notifications.BuildPruneReportNotificationMessage(format, environmentName, result)
}),
Title: defaultTitle,
- NtfyTitle: "🧹 System Prune Complete",
+ NtfyTitle: kit.Ternary(len(result.Errors) > 0, "⚠️ System Prune Finished with Errors", "🧹 System Prune Complete"),
DefaultTitle: defaultTitle,
RenderEmail: func() (string, string, error) {
htmlBody, _, err := s.renderPruneReportEmailTemplateInternal(environmentName, result)
if err != nil {
return "", "", fmt.Errorf("failed to render email template: %w", err)
}
- subject := notifications.BuildEmailSubject(environmentName, fmt.Sprintf("System Prune Report: %s Reclaimed", notifications.FormatBytes(result.SpaceReclaimed)))
+ subject := notifications.BuildEmailSubject(environmentName, fmt.Sprintf(
+ "System Prune Report: %s Reclaimed%s",
+ notifications.FormatBytes(result.SpaceReclaimed),
+ kit.Ternary(len(result.Errors) > 0, fmt.Sprintf(", %d Error(s)", len(result.Errors)), ""),
+ ))
return subject, htmlBody, nil
},
}
@@ -332,6 +337,7 @@ func (s *Service) renderPruneReportEmailTemplateInternal(environmentName string,
"ImageSpaceReclaimed": notifications.FormatBytes(result.ImageSpaceReclaimed),
"VolumeSpaceReclaimed": notifications.FormatBytes(result.VolumeSpaceReclaimed),
"BuildCacheSpaceReclaimed": notifications.FormatBytes(result.BuildCacheSpaceReclaimed),
+ "Status": kit.Ternary(len(result.Errors) > 0, "Finished with errors: "+strings.Join(result.Errors, "; "), "Completed"),
"Time": time.Now().Format(time.RFC1123),
}
diff --git a/backend/internal/updater/service.go b/backend/internal/updater/service.go
index e7c2a37be..0d76995fc 100644
--- a/backend/internal/updater/service.go
+++ b/backend/internal/updater/service.go
@@ -306,7 +306,9 @@ func (s *UpdaterService) applyBatch(ctx context.Context, options arcaneupdater.O
if len(entries) == 0 {
return
}
- if err := s.deps.Notifications.SendBatchContainerUpdateNotification(ctx, entries); err != nil {
+ notifyCtx, cancelNotify := context.WithTimeout(context.WithoutCancel(ctx), timeouts.DefaultHTTPClient)
+ defer cancelNotify()
+ if err := s.deps.Notifications.SendBatchContainerUpdateNotification(notifyCtx, entries); err != nil {
slog.ErrorContext(ctx, "failed to send batched container update notification", "error", err, "count", len(entries))
}
}()
diff --git a/backend/pkg/scheduler/scheduled_prune_job.go b/backend/pkg/scheduler/scheduled_prune_job.go
index a97477542..63b4f8798 100644
--- a/backend/pkg/scheduler/scheduled_prune_job.go
+++ b/backend/pkg/scheduler/scheduled_prune_job.go
@@ -10,6 +10,7 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/notification"
"github.com/getarcaneapp/arcane/backend/v2/internal/settings"
"github.com/getarcaneapp/arcane/backend/v2/internal/system"
+ "github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/timeouts"
scheduleutil "github.com/getarcaneapp/arcane/backend/v2/pkg/scheduler/schedule"
)
@@ -64,6 +65,15 @@ func (j *ScheduledPruneJob) Run(ctx context.Context) (schedulertypes.Outcome, er
)
result, started, err := j.systemService.PruneScheduled(ctx, "0", req)
+ if started {
+ defer func() {
+ notifyCtx, cancelNotify := context.WithTimeout(context.WithoutCancel(ctx), timeouts.DefaultHTTPClient)
+ defer cancelNotify()
+ if sendPruneReportNotificationErr := j.notificationService.SendPruneReportNotification(notifyCtx, result); sendPruneReportNotificationErr != nil {
+ slog.WarnContext(ctx, "failed to send prune report notification", "error", sendPruneReportNotificationErr)
+ }
+ }()
+ }
if err != nil {
slog.ErrorContext(ctx, "scheduled prune run failed", "error", err)
return schedulertypes.Outcome{}, err
@@ -86,10 +96,6 @@ func (j *ScheduledPruneJob) Run(ctx context.Context) (schedulertypes.Outcome, er
slog.DebugContext(ctx, "scheduled prune run errors", "errors", result.Errors)
}
- // Send notification
- if sendPruneReportNotificationErr := j.notificationService.SendPruneReportNotification(ctx, result); sendPruneReportNotificationErr != nil {
- slog.WarnContext(ctx, "failed to send prune report notification", "error", sendPruneReportNotificationErr)
- }
outcome := schedulertypes.Outcome{Status: schedulertypes.Succeeded}
if result.ActivityID != nil {
outcome.ActivityID = *result.ActivityID
diff --git a/backend/pkg/utils/notifications/messages.go b/backend/pkg/utils/notifications/messages.go
index 418e522d2..8d0f74377 100644
--- a/backend/pkg/utils/notifications/messages.go
+++ b/backend/pkg/utils/notifications/messages.go
@@ -352,6 +352,12 @@ func BuildPruneReportNotificationMessage(format MessageFormat, environmentName s
fmt.Fprintf(&message, "🧱 Containers: %s\n", FormatBytes(result.ContainerSpaceReclaimed))
fmt.Fprintf(&message, "💿 Volumes: %s\n", FormatBytes(result.VolumeSpaceReclaimed))
fmt.Fprintf(&message, "🛠️ Build cache: %s\n", FormatBytes(result.BuildCacheSpaceReclaimed))
+ if len(result.Errors) > 0 {
+ fmt.Fprintf(&message, "\n⚠️ **%d error(s)**\n", len(result.Errors))
+ for _, pruneErr := range result.Errors {
+ fmt.Fprintf(&message, "- %s\n", pruneErr)
+ }
+ }
return message.String()
}
@@ -364,6 +370,12 @@ func BuildPruneReportNotificationMessage(format MessageFormat, environmentName s
fmt.Fprintf(&message, "- Images: %s\n", FormatBytes(result.ImageSpaceReclaimed))
fmt.Fprintf(&message, "- Volumes: %s\n", FormatBytes(result.VolumeSpaceReclaimed))
fmt.Fprintf(&message, "- Build Cache: %s\n", FormatBytes(result.BuildCacheSpaceReclaimed))
+ if len(result.Errors) > 0 {
+ fmt.Fprintf(&message, "\n%s\n", formatNotificationLabel(format, "Errors"))
+ for _, pruneErr := range result.Errors {
+ fmt.Fprintf(&message, "- %s\n", pruneErr)
+ }
+ }
return message.String()
}
diff --git a/backend/resources/email-templates/prune-report_html.tmpl b/backend/resources/email-templates/prune-report_html.tmpl
index 17f484965..ddf441943 100644
--- a/backend/resources/email-templates/prune-report_html.tmpl
+++ b/backend/resources/email-templates/prune-report_html.tmpl
@@ -2,7 +2,8 @@
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="text-align:center;margin-bottom:32px"><tbody><tr><td><img alt="Arcane" height="auto" src="{{.LogoURL}}" style="display:inline-block;outline:none;border:none;text-decoration:none;width:180px;height:auto" width="180"/></td></tr></tbody></table><div style="background-color:#31343a;border:1px solid #3a3e45;padding:32px;border-radius:14px;box-shadow:none"><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation"><tbody style="width:100%"><tr style="width:100%"><td data-id="__react-email-column"><h1 style="font-size:24px;font-weight:bold;margin:0;color:#f5f7fa;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace">System Prune Report</h1></td><td align="right" data-id="__react-email-column"></td></tr></tbody></table>
<table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-top:20px;text-align:center;background-color:#2b2e34;border:1px solid #3a3e45;border-radius:10px"><tbody><tr><td style="padding:20px"><p style="font-size:12px;line-height:18px;letter-spacing:0.08em;text-transform:uppercase;color:#9298a3;margin:0;margin-top:0;margin-bottom:0;margin-left:0;margin-right:0">Total Reclaimed</p><p style="font-size:30px;line-height:36px;font-weight:700;color:#34d399;margin:8px 0 0 0;margin-top:8px;margin-right:0;margin-bottom:0;margin-left:0">{{.TotalSpaceReclaimed}}</p></td></tr></tbody></table><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-top:18px;background-color:#2b2e34;border:1px solid #3a3e45;border-radius:10px"><tbody><tr><td style="padding:20px"><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:0">
<tbody style="width:100%"><tr style="width:100%"><td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px"><p style="font-size:14px;line-height:24px;font-weight:600;color:#9298a3;margin:8px 0;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">Environment:</p></td><td data-id="__react-email-column"><p style="font-size:14px;line-height:24px;color:#e6e8ec;margin:8px 0;word-break:break-word;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">{{.Environment}}</p></td></tr></tbody></table><hr style="width:100%;border:none;border-color:#3a3e45;border-top:1px solid #eaeaea;margin:4px 0"/><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:0"><tbody style="width:100%"><tr style="width:100%">
-<td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px"><p style="font-size:14px;line-height:24px;font-weight:600;color:#9298a3;margin:8px 0;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">Containers:</p></td><td data-id="__react-email-column"><p style="font-size:14px;line-height:24px;color:#e6e8ec;margin:8px 0;word-break:break-word;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">{{.ContainerSpaceReclaimed}}</p></td></tr></tbody></table><hr style="width:100%;border:none;border-color:#3a3e45;border-top:1px solid #eaeaea;margin:4px 0"/><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:0"><tbody style="width:100%"><tr style="width:100%"><td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px">
+<td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px"><p style="font-size:14px;line-height:24px;font-weight:600;color:#9298a3;margin:8px 0;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">Status:</p></td><td data-id="__react-email-column"><p style="font-size:14px;line-height:24px;color:#e6e8ec;margin:8px 0;word-break:break-word;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">{{.Status}}</p></td></tr></tbody></table><hr style="width:100%;border:none;border-color:#3a3e45;border-top:1px solid #eaeaea;margin:4px 0"/><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:0"><tbody style="width:100%"><tr style="width:100%"><td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px">
+<p style="font-size:14px;line-height:24px;font-weight:600;color:#9298a3;margin:8px 0;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">Containers:</p></td><td data-id="__react-email-column"><p style="font-size:14px;line-height:24px;color:#e6e8ec;margin:8px 0;word-break:break-word;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">{{.ContainerSpaceReclaimed}}</p></td></tr></tbody></table><hr style="width:100%;border:none;border-color:#3a3e45;border-top:1px solid #eaeaea;margin:4px 0"/><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:0"><tbody style="width:100%"><tr style="width:100%"><td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px">
<p style="font-size:14px;line-height:24px;font-weight:600;color:#9298a3;margin:8px 0;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">Images:</p></td><td data-id="__react-email-column"><p style="font-size:14px;line-height:24px;color:#e6e8ec;margin:8px 0;word-break:break-word;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">{{.ImageSpaceReclaimed}}</p></td></tr></tbody></table><hr style="width:100%;border:none;border-color:#3a3e45;border-top:1px solid #eaeaea;margin:4px 0"/><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:0"><tbody style="width:100%"><tr style="width:100%"><td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px">
<p style="font-size:14px;line-height:24px;font-weight:600;color:#9298a3;margin:8px 0;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">Volumes:</p></td><td data-id="__react-email-column"><p style="font-size:14px;line-height:24px;color:#e6e8ec;margin:8px 0;word-break:break-word;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">{{.VolumeSpaceReclaimed}}</p></td></tr></tbody></table><hr style="width:100%;border:none;border-color:#3a3e45;border-top:1px solid #eaeaea;margin:4px 0"/><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-bottom:0"><tbody style="width:100%"><tr style="width:100%"><td data-id="__react-email-column" style="width:180px;vertical-align:top;padding-right:12px">
<p style="font-size:14px;line-height:24px;font-weight:600;color:#9298a3;margin:8px 0;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">Build Cache:</p></td><td data-id="__react-email-column"><p style="font-size:14px;line-height:24px;color:#e6e8ec;margin:8px 0;word-break:break-word;font-family:&#x27;Geist Mono&#x27;, ui-monospace, SFMono-Regular, Menlo, Monaco, &#x27;Courier New&#x27;, monospace;margin-top:8px;margin-right:0;margin-bottom:8px;margin-left:0">{{.BuildCacheSpaceReclaimed}}</p></td></tr></tbody></table></td></tr></tbody></table><table align="center" width="100%" border="0" cellPadding="0" cellSpacing="0" role="presentation" style="margin-top:20px"><tbody><tr><td><p style="font-size:12px;line-height:18px;color:#9298a3;margin:0;margin-top:0;margin-bottom:0;margin-left:0;margin-right:0">Generated by Arcane at <!-- -->{{.Time}}</p></td></tr></tbody></table></div>
diff --git a/backend/resources/email-templates/prune-report_text.tmpl b/backend/resources/email-templates/prune-report_text.tmpl
index bb50bb522..d92cd11ed 100644
--- a/backend/resources/email-templates/prune-report_text.tmpl
+++ b/backend/resources/email-templates/prune-report_text.tmpl
@@ -10,6 +10,12 @@ Environment:
----------------------------------------
+Status:
+
+{{.Status}}
+
+----------------------------------------
+
Containers:
{{.ContainerSpaceReclaimed}}
diff --git a/email-templates/emails/prune-report.tsx b/email-templates/emails/prune-report.tsx
index 68262dd42..72ddc00c5 100644
--- a/email-templates/emails/prune-report.tsx
+++ b/email-templates/emails/prune-report.tsx
@@ -13,6 +13,7 @@ interface PruneReportEmailProps {
imageSpaceReclaimed: string;
volumeSpaceReclaimed: string;
buildCacheSpaceReclaimed: string;
+ status: string;
time: string;
}
@@ -25,6 +26,7 @@ export const PruneReportEmail = ({
imageSpaceReclaimed,
volumeSpaceReclaimed,
buildCacheSpaceReclaimed,
+ status,
time
}: PruneReportEmailProps) => {
return (
@@ -48,6 +50,17 @@ export const PruneReportEmail = ({
<Hr style={dividerStyle} />
+ <Row style={infoRowStyle}>
+ <Column style={labelColumnStyle}>
+ <Text style={labelStyle}>Status:</Text>
+ </Column>
+ <Column>
+ <Text style={valueStyle}>{status}</Text>
+ </Column>
+ </Row>
+
+ <Hr style={dividerStyle} />
+
<Row style={infoRowStyle}>
<Column style={labelColumnStyle}>
<Text style={labelStyle}>Containers:</Text>
@@ -178,6 +191,7 @@ PruneReportEmail.TemplateProps = {
imageSpaceReclaimed: '{{.ImageSpaceReclaimed}}',
volumeSpaceReclaimed: '{{.VolumeSpaceReclaimed}}',
buildCacheSpaceReclaimed: '{{.BuildCacheSpaceReclaimed}}',
+ status: '{{.Status}}',
time: '{{.Time}}'
};
@@ -188,5 +202,6 @@ PruneReportEmail.PreviewProps = {
imageSpaceReclaimed: '2.1 GB',
volumeSpaceReclaimed: '612 MB',
buildCacheSpaceReclaimed: '228 MB',
+ status: 'Completed',
time: 'Tue, 10 Feb 2026 19:30:00 UTC'
};