feat/security
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m44s
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m44s
Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
62
lib/server/cleanup.go
Normal file
62
lib/server/cleanup.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"warpbox/lib/boxstore"
|
||||
)
|
||||
|
||||
func (app *App) runExpiredCleanup(trigger string) (boxstore.CleanupExpiredResult, error) {
|
||||
result, err := boxstore.CleanupExpiredBoxes()
|
||||
if err != nil {
|
||||
log.Printf("warpbox cleanup[%s] failed: %v", trigger, err)
|
||||
app.logActivity("boxes.cleanup.failed", "high", "Expired boxes cleanup failed", nil, map[string]string{
|
||||
"trigger": trigger,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
meta := map[string]string{
|
||||
"trigger": trigger,
|
||||
"scanned": intToString(result.Scanned),
|
||||
"deleted": intToString(result.Deleted),
|
||||
"skipped": intToString(result.Skipped),
|
||||
}
|
||||
if len(result.DeletedIDs) > 0 {
|
||||
limit := len(result.DeletedIDs)
|
||||
if limit > 20 {
|
||||
limit = 20
|
||||
}
|
||||
meta["deleted_ids"] = strings.Join(result.DeletedIDs[:limit], ",")
|
||||
}
|
||||
if len(result.Warnings) > 0 {
|
||||
limit := len(result.Warnings)
|
||||
if limit > 3 {
|
||||
limit = 3
|
||||
}
|
||||
meta["warnings"] = strings.Join(result.Warnings[:limit], " | ")
|
||||
}
|
||||
app.logActivity("boxes.cleanup", "medium", "Expired boxes cleanup run completed", nil, meta)
|
||||
log.Printf("warpbox cleanup[%s] scanned=%d deleted=%d skipped=%d", trigger, result.Scanned, result.Deleted, result.Skipped)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (app *App) startExpiredCleanupWorker() {
|
||||
if app == nil || app.config == nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
interval := app.config.ExpiredCleanupIntervalSeconds
|
||||
if interval <= 0 {
|
||||
time.Sleep(30 * time.Second)
|
||||
continue
|
||||
}
|
||||
time.Sleep(time.Duration(interval) * time.Second)
|
||||
_, _ = app.runExpiredCleanup("worker")
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user