Add live activity progress and logs

This commit is contained in:
Mikei386
2026-06-14 14:26:13 +02:00
parent 5a1b9588e1
commit 3e3c63070e
14 changed files with 254 additions and 38 deletions
+21 -1
View File
@@ -35,11 +35,24 @@ type Summary struct {
TotalFilesProcessed int64 `json:"total_files_processed"`
}
type Progress struct {
MessageType string `json:"message_type"`
PercentDone float64 `json:"percent_done"`
TotalFiles int64 `json:"total_files"`
FilesDone int64 `json:"files_done"`
TotalBytes int64 `json:"total_bytes"`
BytesDone int64 `json:"bytes_done"`
SecondsRemaining int64 `json:"seconds_remaining"`
CurrentFiles []string `json:"current_files"`
}
type ProgressCallback func(Progress)
func (r *Runner) Init(ctx context.Context, repo model.Repository) error {
return r.run(ctx, repo, []string{"init"}, nil, nil)
}
func (r *Runner) Backup(ctx context.Context, repo model.Repository, job model.Job, sources []string) (Summary, error) {
func (r *Runner) Backup(ctx context.Context, repo model.Repository, job model.Job, sources []string, progress ProgressCallback) (Summary, error) {
args := []string{"backup", "--json", "--compression", job.Compression}
for _, tag := range append([]string{"backupper", "job:" + job.ID}, job.Tags...) {
args = append(args, "--tag", tag)
@@ -50,6 +63,13 @@ func (r *Runner) Backup(ctx context.Context, repo model.Repository, job model.Jo
args = append(args, sources...)
var summary Summary
err := r.run(ctx, repo, args, func(line []byte) {
var status Progress
if json.Unmarshal(line, &status) == nil && status.MessageType == "status" {
if progress != nil {
progress(status)
}
return
}
var candidate Summary
if json.Unmarshal(line, &candidate) == nil && candidate.MessageType == "summary" {
summary = candidate