mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Add Move retention policy
* Currently not testet!
This commit is contained in:
parent
6731b8b1e0
commit
0f9b83e636
@ -446,7 +446,7 @@ func main() {
|
|||||||
|
|
||||||
switch cfg.Retention.Policy {
|
switch cfg.Retention.Policy {
|
||||||
case "delete":
|
case "delete":
|
||||||
log.Info("Register retention service")
|
log.Info("Register retention delete service")
|
||||||
|
|
||||||
s.Every(1).Day().At("4:00").Do(func() {
|
s.Every(1).Day().At("4:00").Do(func() {
|
||||||
startTime := time.Now().Unix() - int64(cfg.Retention.Age*24*3600)
|
startTime := time.Now().Unix() - int64(cfg.Retention.Age*24*3600)
|
||||||
@ -469,7 +469,28 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
case "move":
|
case "move":
|
||||||
log.Warn("Retention policy move not implemented")
|
log.Info("Register retention move service")
|
||||||
|
|
||||||
|
s.Every(1).Day().At("4:00").Do(func() {
|
||||||
|
startTime := time.Now().Unix() - int64(cfg.Retention.Age*24*3600)
|
||||||
|
jobs, err := jobRepo.FindJobsBefore(startTime)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("Error while looking for retention jobs: %s", err.Error())
|
||||||
|
}
|
||||||
|
archive.GetHandle().Move(jobs, cfg.Retention.Location)
|
||||||
|
|
||||||
|
if cfg.Retention.IncludeDB {
|
||||||
|
cnt, err := jobRepo.DeleteJobsBefore(startTime)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Error while deleting retention jobs from db: %s", err.Error())
|
||||||
|
} else {
|
||||||
|
log.Infof("Retention: Removed %d jobs from db", cnt)
|
||||||
|
}
|
||||||
|
if err = jobRepo.Optimize(); err != nil {
|
||||||
|
log.Errorf("Error occured in db optimization: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Compression > 0 {
|
if cfg.Compression > 0 {
|
||||||
|
@ -36,6 +36,8 @@ type ArchiveBackend interface {
|
|||||||
|
|
||||||
CleanUp(jobs []*schema.Job)
|
CleanUp(jobs []*schema.Job)
|
||||||
|
|
||||||
|
Move(jobs []*schema.Job, path string)
|
||||||
|
|
||||||
Clean(before int64, after int64)
|
Clean(before int64, after int64)
|
||||||
|
|
||||||
Compress(jobs []*schema.Job)
|
Compress(jobs []*schema.Job)
|
||||||
|
@ -302,6 +302,27 @@ func (fsa *FsArchive) Clean(before int64, after int64) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fsa *FsArchive) Move(jobs []*schema.Job, path string) {
|
||||||
|
for _, job := range jobs {
|
||||||
|
source := getDirectory(job, fsa.path)
|
||||||
|
target := getDirectory(job, path)
|
||||||
|
|
||||||
|
if err := os.MkdirAll(filepath.Clean(filepath.Join(target, "..")), 0777); err != nil {
|
||||||
|
log.Errorf("JobArchive Move MkDir error: %v", err)
|
||||||
|
}
|
||||||
|
if err := os.Rename(source, target); err != nil {
|
||||||
|
log.Errorf("JobArchive Move() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
parent := filepath.Clean(filepath.Join(source, ".."))
|
||||||
|
if util.GetFilecount(parent) == 0 {
|
||||||
|
if err := os.Remove(parent); err != nil {
|
||||||
|
log.Errorf("JobArchive Move() error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (fsa *FsArchive) CleanUp(jobs []*schema.Job) {
|
func (fsa *FsArchive) CleanUp(jobs []*schema.Job) {
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
dir := getDirectory(job, fsa.path)
|
dir := getDirectory(job, fsa.path)
|
||||||
|
Loading…
Reference in New Issue
Block a user