Probleme mit Deadlocks durch Timeout im Ctx verhindern.
This commit is contained in:
parent
b3367d8e5e
commit
6f75f05e06
|
|
@ -48,10 +48,6 @@ 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) {
|
func (f *ElioDateiFoo) ScanCsv(ctx context.Context, data chan<- CountryCsvData) {
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
fmt.Println("Abbruch angefordert im Verarbeitungsprozess.")
|
|
||||||
default:
|
|
||||||
files, err := os.ReadDir(f.lookUpDir)
|
files, err := os.ReadDir(f.lookUpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
@ -93,10 +89,11 @@ func (f *ElioDateiFoo) ScanCsv(ctx context.Context, data chan<- CountryCsvData)
|
||||||
f.mu.Lock()
|
f.mu.Lock()
|
||||||
f.haveDone[v.filename] = time.Now()
|
f.haveDone[v.filename] = time.Now()
|
||||||
f.mu.Unlock()
|
f.mu.Unlock()
|
||||||
|
go func() {
|
||||||
//Max 5 Sekunden zum Abarbeiten eines Datensatzes
|
//Max 5 Sekunden zum Abarbeiten eines Datensatzes
|
||||||
tctx, cancel := context.WithTimeout(ctx, time.Second*5)
|
tctx, cancel := context.WithTimeout(ctx, time.Second*5)
|
||||||
f.process(tctx, v.filename, data)
|
f.process(tctx, v.filename, data)
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue