Skip to content

Commit

Permalink
track salvage progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dahn510 committed Aug 22, 2024
1 parent 7f74594 commit 8d746bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
26 changes: 26 additions & 0 deletions api/recycle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package api

import (
"net/http"

"github.com/JackalLabs/sequoia/api/types"
"github.com/JackalLabs/sequoia/recycle"
"github.com/rs/zerolog/log"
)

func RecycleSalvageHandler(rd *recycle.RecycleDepot) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
v := types.RecycleSalvageResponse{
TotalJackalProviderFiles: rd.TotalJprovFiles,
SalvagedFilesCount: rd.SalvagedFilesCount,
IsSalvageFinished: rd.SalvagedFilesCount == rd.TotalJprovFiles,
}

err := json.NewEncoder(w).Encode(v)
if err != nil {
log.Error().Err(err)
return
}
}

}
8 changes: 5 additions & 3 deletions recycle/recycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ func (r *RecycleDepot) SalvageFiles(jprovdHome string) error {
log.Error().Err(err).Msg("failed to read jprovd storage directory")
return err
}
r.TotalJprovFiles = int64(len(dirList))

lastSalvaged, err := r.lastSalvagedFile(recordFile)
if err != nil {
return err
}
lastSalvagedFound := false

salvaged := 0
r.SalvagedFilesCount = 0
for _, d := range dirList {
if !d.IsDir() {
continue
Expand All @@ -107,6 +108,7 @@ func (r *RecycleDepot) SalvageFiles(jprovdHome string) error {
if d.Name() == lastSalvaged {
lastSalvagedFound = true
}
r.SalvagedFilesCount++
continue // skip the last salvage record to avoid duplicate
}

Expand All @@ -132,10 +134,10 @@ func (r *RecycleDepot) SalvageFiles(jprovdHome string) error {
Msg("failed to record salvage info")
}

salvaged++
r.SalvagedFilesCount++
}

log.Info().Int("count", salvaged).Msg("salvaging finished...")
log.Info().Int("count", int(r.SalvagedFilesCount)).Msg("salvaging finished...")
return nil
}

Expand Down

0 comments on commit 8d746bd

Please sign in to comment.