Skip to content

Commit

Permalink
feat: add CONDITION_SNAPSHOT_WARNING hook triggered by any warning st…
Browse files Browse the repository at this point in the history
…atus at the completion of a snapshot
  • Loading branch information
garethgeorge committed May 5, 2024
1 parent 5a996d7 commit f0ee20f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
31 changes: 18 additions & 13 deletions gen/go/v1/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion internal/hook/hookvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (v HookVars) Summary() (string, error) {
return v.renderTemplate(templateForError)
case v1.Hook_CONDITION_SNAPSHOT_ERROR:
return v.renderTemplate(templateForError)
case v1.Hook_CONDITION_SNAPSHOT_WARNING:
return v.renderTemplate(templateForError)
default:
return "unknown event", nil
}
Expand Down Expand Up @@ -151,7 +153,10 @@ Backrest Notification for Error
Task: "{{ .Task }}" at {{ .FormatTime .CurTime }}
{{ if .Error -}}
Error: {{ .Error }}
{{ end }}`
{{ end }}
{{ if .Items -}}
`

var templateForSnapshotStart = `
Backrest Notification for Snapshot Start
Expand Down
5 changes: 5 additions & 0 deletions internal/orchestrator/tasks/taskbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (t *BackupTask) Run(ctx context.Context, st ScheduledTask, runner TaskRunne
v1.Hook_CONDITION_ANY_ERROR,
}, vars)
return err
} else {
vars.Error = fmt.Sprintf("partial backup, %d files may not have been read completely.", len(backupOp.OperationBackup.Errors))
runner.ExecuteHooks([]v1.Hook_Condition{
v1.Hook_CONDITION_SNAPSHOT_WARNING,
}, vars)
}
op.Status = v1.OperationStatus_STATUS_WARNING
op.DisplayMessage = "Partial backup, some files may not have been read completely."
Expand Down
1 change: 1 addition & 0 deletions proto/v1/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ message Hook {
CONDITION_SNAPSHOT_START = 2; // backup started.
CONDITION_SNAPSHOT_END = 3; // backup completed (success or fail).
CONDITION_SNAPSHOT_ERROR = 4; // snapshot failed.
CONDITION_SNAPSHOT_WARNING = 5; // snapshot completed with warnings.
}

enum OnError {
Expand Down
8 changes: 8 additions & 0 deletions webui/gen/ts/v1/config_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ export enum Hook_Condition {
* @generated from enum value: CONDITION_SNAPSHOT_ERROR = 4;
*/
SNAPSHOT_ERROR = 4,

/**
* snapshot completed with warnings.
*
* @generated from enum value: CONDITION_SNAPSHOT_WARNING = 5;
*/
SNAPSHOT_WARNING = 5,
}
// Retrieve enum metadata with: proto3.getEnumType(Hook_Condition)
proto3.util.setEnumType(Hook_Condition, "v1.Hook.Condition", [
Expand All @@ -661,6 +668,7 @@ proto3.util.setEnumType(Hook_Condition, "v1.Hook.Condition", [
{ no: 2, name: "CONDITION_SNAPSHOT_START" },
{ no: 3, name: "CONDITION_SNAPSHOT_END" },
{ no: 4, name: "CONDITION_SNAPSHOT_ERROR" },
{ no: 5, name: "CONDITION_SNAPSHOT_WARNING" },
]);

/**
Expand Down

0 comments on commit f0ee20f

Please sign in to comment.