Skip to content

Commit

Permalink
use log file for task end time
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol committed Nov 17, 2024
1 parent 5afbd25 commit ca7d180
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
10 changes: 10 additions & 0 deletions internal/store/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func (store *Store) GetJob(id string) (*Job, error) {
return nil, fmt.Errorf("GetJob: error scanning job row -> %w", err)
}

exclusions, err := store.GetAllJobExclusions(id)
if err == nil {
job.Exclusions = exclusions
}

if job.LastRunUpid != nil {
task, err := store.GetTaskByUPID(*job.LastRunUpid)
if err != nil {
Expand Down Expand Up @@ -324,6 +329,11 @@ func (store *Store) GetAllJobs() ([]Job, error) {
return nil, fmt.Errorf("GetAllJobs: error scanning job row -> %w", err)
}

exclusions, err := store.GetAllJobExclusions(job.ID)
if err == nil {
job.Exclusions = exclusions
}

if job.LastRunUpid != nil {
task, err := store.GetTaskByUPID(*job.LastRunUpid)
if err != nil {
Expand Down
33 changes: 10 additions & 23 deletions internal/store/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package store
import (
"fmt"
"net/http"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -95,35 +96,21 @@ func (storeInstance *Store) GetTaskByUPID(upid string) (*Task, error) {
}

func (storeInstance *Store) GetTaskEndTime(task *Task) (int64, error) {
nextPage := true
var resp TasksResponse

if storeInstance.LastToken == nil && storeInstance.APIToken == nil {
return -1, fmt.Errorf("GetTaskEndTime: token is required")
}

page := 1
for nextPage {
start := (page - 1) * 50
err := storeInstance.ProxmoxHTTPRequest(
http.MethodGet,
fmt.Sprintf("/api2/json/nodes/localhost/tasks?typefilter=backup&running=false&start=%d&since=%d", start, task.StartTime),
nil,
&resp,
)
if err != nil {
return -1, fmt.Errorf("GetTaskEndTime: error creating http request -> %w", err)
}
upidSplit := strings.Split(task.UPID, ":")
if len(upidSplit) < 4 {
return -1, fmt.Errorf("GetTaskEndTime: error getting tasks: invalid upid")
}

for _, respTask := range resp.Data {
if respTask.UPID == task.UPID {
return respTask.EndTime, nil
}
}
parsed := upidSplit[3]
logFolder := parsed[len(parsed)-2:]

if resp.Total <= page*50 {
nextPage = false
}
logStat, err := os.Stat(fmt.Sprintf("/var/log/proxmox-backup/tasks/%s/%s", logFolder, task.UPID))
if err == nil {
return logStat.ModTime().Unix(), nil
}

return -1, fmt.Errorf("GetTaskEndTime: error getting tasks: not found")
Expand Down

0 comments on commit ca7d180

Please sign in to comment.