Delete expired files

master v0.2.0
Caj Larsson 3 years ago
parent 2ce12745a6
commit 53531373b9

@ -124,9 +124,7 @@ func (s SwampFileService) CleanUpExpiredFiles() error {
expiry := time.Now().Add(-ns.AllowanceDuration) expiry := time.Now().Add(-ns.AllowanceDuration)
dfs, err := s.swamp_file_repo.DeleteOlderThan(strconv.FormatInt(ns.ID, 10), expiry) dfs, err := s.swamp_file_repo.DeleteOlderThan(strconv.FormatInt(ns.ID, 10), expiry)
// panic(errors.New(fmt.Sprintf("%+v", dfs)))
for _, df := range dfs { for _, df := range dfs {
ns.FileQuota.Remove(df.Size) ns.FileQuota.Remove(df.Size)
} }

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
// "io" "time"
"caj-larsson/bog/dataswamp" "caj-larsson/bog/dataswamp"
"caj-larsson/bog/dataswamp/namespace" "caj-larsson/bog/dataswamp/namespace"
"caj-larsson/bog/dataswamp/swampfile" "caj-larsson/bog/dataswamp/swampfile"
@ -31,7 +31,7 @@ func buildFileDataRepository(config FileConfig) swampfile.Repository {
return r return r
} }
func buildUserAgentRepository(config DatabaseConfig) namespace.Repository { func buildNamespaceRepository(config DatabaseConfig) namespace.Repository {
if config.Backend != "sqlite" { if config.Backend != "sqlite" {
panic("Can only handle sqlite") panic("Can only handle sqlite")
} }
@ -84,15 +84,22 @@ func (b *Bog) routes() {
b.router.HandleFunc("/", b.fileHandler) b.router.HandleFunc("/", b.fileHandler)
} }
func (b *Bog) cleanNamespaces(){
for true {
b.file_service.CleanUpExpiredFiles()
time.Sleep(time.Minute * 10)
}
}
func New(config *Configuration) *Bog { func New(config *Configuration) *Bog {
b := new(Bog) b := new(Bog)
b.address = config.bindAddress() b.address = config.bindAddress()
fsSwampRepo := buildFileDataRepository(config.File) fsSwampRepo := buildFileDataRepository(config.File)
uaRepo := buildUserAgentRepository(config.Database) nsRepo := buildNamespaceRepository(config.Database)
b.file_service = dataswamp.NewSwampFileService( b.file_service = dataswamp.NewSwampFileService(
uaRepo, fsSwampRepo, config.Quota.ParsedSizeBytes(), config.Quota.ParsedDuration(), nsRepo, fsSwampRepo, config.Quota.ParsedSizeBytes(), config.Quota.ParsedDuration(),
) )
b.router = new(http.ServeMux) b.router = new(http.ServeMux)
@ -101,5 +108,6 @@ func New(config *Configuration) *Bog {
} }
func (b *Bog) Run() { func (b *Bog) Run() {
go b.cleanNamespaces()
http.ListenAndServe(b.address, b.router) http.ListenAndServe(b.address, b.router)
} }

Loading…
Cancel
Save