ImportMap Havedone mit allen Einträgen älter als 60 Minuten bereinigen
This commit is contained in:
parent
3393adf5f8
commit
28cf9d7acd
|
|
@ -28,17 +28,19 @@ type CountryCsvData struct {
|
||||||
type ElioHandleFunc func(ctx context.Context, filename string, data chan<- CountryCsvData) bool
|
type ElioHandleFunc func(ctx context.Context, filename string, data chan<- CountryCsvData) bool
|
||||||
|
|
||||||
type ElioDateiFoo struct {
|
type ElioDateiFoo struct {
|
||||||
process ElioHandleFunc
|
process ElioHandleFunc
|
||||||
lookUpDir string
|
lookUpDir string
|
||||||
processedDir string
|
processedDir string
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
haveDone map[string]time.Time
|
haveDone map[string]time.Time
|
||||||
|
clearHaveDoneRunning bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewElioDateiFoo(lookUpDir string, process ElioHandleFunc) *ElioDateiFoo {
|
func NewElioDateiFoo(lookUpDir string, process ElioHandleFunc) *ElioDateiFoo {
|
||||||
df := ElioDateiFoo{lookUpDir: lookUpDir,
|
df := ElioDateiFoo{lookUpDir: lookUpDir,
|
||||||
process: process,
|
process: process,
|
||||||
haveDone: make(map[string]time.Time),
|
haveDone: make(map[string]time.Time),
|
||||||
|
clearHaveDoneRunning: false,
|
||||||
}
|
}
|
||||||
return &df
|
return &df
|
||||||
}
|
}
|
||||||
|
|
@ -49,6 +51,30 @@ func NewElioDateiFoo(lookUpDir string, process ElioHandleFunc) *ElioDateiFoo {
|
||||||
// Veraltete Dateien mit Präfix no-import und Postifx .old benennen.
|
// Veraltete Dateien mit Präfix no-import und Postifx .old benennen.
|
||||||
// Gültige Dateinamen zur Extraktion in Closure übergeben.
|
// Gültige Dateinamen zur Extraktion in Closure übergeben.
|
||||||
func (f *ElioDateiFoo) ScanCsv(ctx context.Context, data chan<- CountryCsvData) error {
|
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)
|
files, err := os.ReadDir(f.lookUpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue