Added HaveDone Map and Gofunc for Working with CSV

This commit is contained in:
Marco Kittel 2025-06-29 00:24:42 +02:00
parent a0ab9a6f34
commit c3826f7f92
1 changed files with 15 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"sync"
"time"
"gittea.marcokittel.de/elio/eliotools/tools"
@ -21,11 +22,14 @@ type ElioDateiFoo struct {
process ElioHandleFunc
lookUpDir string
processedDir string
mu sync.RWMutex
haveDone map[string]time.Time
}
func NewElioDateiFoo(lookUpDir string, process ElioHandleFunc) *ElioDateiFoo {
df := ElioDateiFoo{lookUpDir: lookUpDir,
process: process,
haveDone: make(map[string]time.Time),
}
return &df
}
@ -65,6 +69,15 @@ func (f *ElioDateiFoo) ScanCsv() {
}
}
for _, v := range filemap {
f.process(v.filename)
f.mu.RLock()
_, ok := f.haveDone[v.filename]
f.mu.RUnlock()
if ok {
break
}
f.mu.Lock()
f.haveDone[v.filename] = time.Now()
f.mu.Unlock()
go f.process(v.filename)
}
}