Skip to content

Commit

Permalink
add since argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 4, 2024
1 parent 945a860 commit 210ffe9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
35 changes: 12 additions & 23 deletions internal/backend/backup/jobrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,46 +96,35 @@ func RunBackup(job *store.Job, storeInstance *store.Store) (*store.Task, error)
return nil, fmt.Errorf("RunBackup: proxmox-backup-client start error (%s) -> %w", cmd.String(), err)
}

timeStarted := time.Now()

for {
line, err := logBuffer.ReadString('\n')
if err != nil && line != "" {
return nil, fmt.Errorf("RunBackup: log buffer readString error -> %w", err)
}

if strings.Contains(line, "Starting backup protocol") {
if strings.Contains(line, "Upload directory") {
break
}

time.Sleep(time.Millisecond * 100)
}

var task *store.Task
for {
task, err = storeInstance.GetMostRecentTask(job)
if err != nil {
_ = cmd.Process.Kill()
if agentMount != nil {
agentMount.Unmount()
}

return nil, fmt.Errorf("RunBackup: unable to get most recent task -> %w", err)
}
time.Sleep(time.Millisecond * 500)

if task.WorkerType == "backup" {
break
}

if cmd.ProcessState != nil {
break
task, err := storeInstance.GetMostRecentTask(job, &timeStarted)
if err != nil {
_ = cmd.Process.Kill()
if agentMount != nil {
agentMount.Unmount()
}

time.Sleep(time.Millisecond * 500)
return nil, fmt.Errorf("RunBackup: unable to get most recent task -> %w", err)
}

if task != nil {
job.LastRunUpid = &task.UPID
job.LastRunState = &task.Status
}
job.LastRunUpid = &task.UPID
job.LastRunState = &task.Status

err = storeInstance.UpdateJob(*job)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/store/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"fmt"
"net/http"
"time"
)

type TasksResponse struct {
Expand All @@ -29,11 +30,11 @@ type Task struct {
ExitStatus string `json:"exitstatus"`
}

func (storeInstance *Store) GetMostRecentTask(job *Job) (*Task, error) {
func (storeInstance *Store) GetMostRecentTask(job *Job, since *time.Time) (*Task, error) {
var resp TasksResponse
err := storeInstance.ProxmoxHTTPRequest(
http.MethodGet,
fmt.Sprintf("/api2/json/nodes/localhost/tasks?store=%s&typefilter=backup&limit=1", job.Store),
fmt.Sprintf("/api2/json/nodes/localhost/tasks?store=%s&typefilter=backup&limit=1&since=%d", job.Store, since.Unix()),
nil,
&resp,
)
Expand Down

0 comments on commit 210ffe9

Please sign in to comment.