Added HaveDone Map and Gofunc for Working with CSV
This commit is contained in:
parent
a0ab9a6f34
commit
c3826f7f92
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gittea.marcokittel.de/elio/eliotools/tools"
|
"gittea.marcokittel.de/elio/eliotools/tools"
|
||||||
|
|
@ -21,11 +22,14 @@ type ElioDateiFoo struct {
|
||||||
process ElioHandleFunc
|
process ElioHandleFunc
|
||||||
lookUpDir string
|
lookUpDir string
|
||||||
processedDir string
|
processedDir string
|
||||||
|
mu sync.RWMutex
|
||||||
|
haveDone map[string]time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
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),
|
||||||
}
|
}
|
||||||
return &df
|
return &df
|
||||||
}
|
}
|
||||||
|
|
@ -65,6 +69,15 @@ func (f *ElioDateiFoo) ScanCsv() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, v := range filemap {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue