Commit ed27f105 authored by Ronny Bangsund's avatar Ronny Bangsund

Moved janitor to utility.go and fixed timing bug.

parent 851616f6
...@@ -44,18 +44,3 @@ func fexists(path string) bool { ...@@ -44,18 +44,3 @@ func fexists(path string) bool {
_, err := os.Stat(path) _, err := os.Stat(path)
return err == nil return err == nil
} }
func initJanitor(s *Scrap) {
delay := s.Expiry - time.Now().Unix()
ticker := time.NewTicker(time.Duration(delay))
go func() {
for {
select {
case <-ticker.C:
ticker.Stop()
s.delete()
return
}
}
}()
}
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"strings" "strings"
"time"
) )
func sane(s string) string { func sane(s string) string {
...@@ -12,3 +13,20 @@ func validLanguage(s string) bool { ...@@ -12,3 +13,20 @@ func validLanguage(s string) bool {
_, ok := languages[s] _, ok := languages[s]
return ok return ok
} }
func initJanitor(s *Scrap) {
delay := s.Expiry - time.Now().Unix()
info("Expiry set to %d", delay)
ticker := time.NewTicker(time.Duration(delay) * time.Second)
go func() {
for {
select {
case <-ticker.C:
ticker.Stop()
info("Janitor: Deleting %s", s.Hash)
s.delete()
return
}
}
}()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment