diff --git a/eliofile/eliofile.go b/eliofile/eliofile.go index ba7a7fe..9ed115f 100644 --- a/eliofile/eliofile.go +++ b/eliofile/eliofile.go @@ -28,17 +28,19 @@ type CountryCsvData struct { type ElioHandleFunc func(ctx context.Context, filename string, data chan<- CountryCsvData) bool type ElioDateiFoo struct { - process ElioHandleFunc - lookUpDir string - processedDir string - mu sync.RWMutex - haveDone map[string]time.Time + process ElioHandleFunc + lookUpDir string + processedDir string + mu sync.RWMutex + haveDone map[string]time.Time + clearHaveDoneRunning bool } func NewElioDateiFoo(lookUpDir string, process ElioHandleFunc) *ElioDateiFoo { df := ElioDateiFoo{lookUpDir: lookUpDir, - process: process, - haveDone: make(map[string]time.Time), + process: process, + haveDone: make(map[string]time.Time), + clearHaveDoneRunning: false, } return &df } @@ -49,6 +51,30 @@ func NewElioDateiFoo(lookUpDir string, process ElioHandleFunc) *ElioDateiFoo { // Veraltete Dateien mit Präfix no-import und Postifx .old benennen. // Gültige Dateinamen zur Extraktion in Closure übergeben. func (f *ElioDateiFoo) ScanCsv(ctx context.Context, data chan<- CountryCsvData) error { + //Importnamen die vor einer Stunde importiert wurden aus der Map aufräumen. + if !f.clearHaveDoneRunning { + f.clearHaveDoneRunning = true + go func() { + for { + select { + case <-ctx.Done(): + default: + time.Sleep(time.Minute * 1) + f.mu.RLock() + jetzt := time.Now() + for k, v := range f.haveDone { + if jetzt.Unix() > v.Add(time.Minute*60).Unix() { + f.mu.Lock() + delete(f.haveDone, k) + f.mu.Unlock() + } + } + f.mu.RUnlock() + } + } + }() + } + files, err := os.ReadDir(f.lookUpDir) if err != nil { return err