Skip to content

Commit

Permalink
convert reader task to backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 4, 2024
1 parent 1acce9c commit a4f96f9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/store/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package store
import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -46,6 +48,23 @@ func (storeInstance *Store) GetMostRecentTask(job *Job, since *time.Time) (*Task
return nil, fmt.Errorf("GetMostRecentTask: error getting tasks: not found")
}

if strings.Contains(resp.Data[0].UPID, ":reader:") {
resp.Data[0].UPID = strings.ReplaceAll(resp.Data[0].UPID, ":reader:", ":backup:")
splittedUPID := strings.Split(resp.Data[0].UPID, ":")
currInVal, err := strconv.ParseInt(splittedUPID[4], 16, 64)
if err != nil {
return nil, fmt.Errorf("GetMostRecentTask: error converting hex -> %w", err)
}
splittedUPID[4] = fmt.Sprintf("%08X", currInVal-1)
idx := strings.LastIndex(splittedUPID[7], "-")
if idx != -1 {
splittedUPID[7] = splittedUPID[7][:idx]
}

resp.Data[0].UPID = strings.Join(splittedUPID, ":")
resp.Data[0].WorkerType = "backup"
}

return &resp.Data[0], nil
}

Expand Down

0 comments on commit a4f96f9

Please sign in to comment.