From 28cf9d7acd9a72437f4fa30231e3618cf8b579ed Mon Sep 17 00:00:00 2001 From: Marco Kittel Date: Sun, 29 Jun 2025 21:12:42 +0200 Subject: [PATCH] =?UTF-8?q?ImportMap=20Havedone=20mit=20allen=20Eintr?= =?UTF-8?q?=C3=A4gen=20=C3=A4lter=20als=2060=20Minuten=20bereinigen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eliofile/eliofile.go | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) 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