54 lines
931 B
Go
54 lines
931 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"sync"
|
|
"syscall"
|
|
"time"
|
|
|
|
"gittea.marcokittel.de/elio/eliotools/datawriter/internal/app"
|
|
"gittea.marcokittel.de/elio/eliotools/datawriter/internal/dbwriter"
|
|
)
|
|
|
|
const (
|
|
NewDir = "/new"
|
|
ProcessedDir = "/processed"
|
|
Rights = 0755
|
|
StockMustHaveFileLen = 38
|
|
)
|
|
|
|
func db(ctx context.Context, app *app.App, wg *sync.WaitGroup) {
|
|
defer wg.Done()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
default:
|
|
//Hier nach neuen Dateien suchen
|
|
err := app.AppendData(dbwriter.MyStruct{A: "bla", B: 4})
|
|
if err != nil {
|
|
//todo
|
|
}
|
|
time.Sleep(time.Second * 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
|
|
ctx, cancel := signal.NotifyContext(
|
|
context.Background(),
|
|
os.Interrupt,
|
|
syscall.SIGTERM,
|
|
)
|
|
defer cancel()
|
|
var wg sync.WaitGroup
|
|
app := app.NewApp(NewDir, ProcessedDir, Rights, &wg)
|
|
wg.Add(1)
|
|
go db(ctx, app, &wg)
|
|
app.Run()
|
|
wg.Wait()
|
|
}
|