Die Häufigkeit der Ausführung des Algorithmus kann nun gesteuert werden
This commit is contained in:
parent
fc32a93522
commit
05c39558ea
2 changed files with 17 additions and 12 deletions
|
@ -15,6 +15,7 @@ services:
|
|||
- MAX_RESULTS=200
|
||||
- DURATION=240
|
||||
- DELETE_AFTER_MINUTES=30
|
||||
- UPDATE_INTERVAL_MINUTES=3
|
||||
# Hildesheim HBF, Braunschweig HBF, Hannover HBF
|
||||
- STATION_IDS=8000169,8000049,8000152
|
||||
restart: always
|
||||
|
|
16
main.go
16
main.go
|
@ -78,6 +78,12 @@ func main() {
|
|||
}
|
||||
stationIDs := strings.Split(os.Getenv("STATION_IDS"), ",")
|
||||
|
||||
updateInterval, err := strconv.Atoi(os.Getenv("UPDATE_INTERVAL_MINUTES"))
|
||||
if err != nil || updateInterval <= 0 {
|
||||
log.Println("Ungültiger oder fehlender Wert für UPDATE_INTERVAL_MINUTES, verwende Standardwert von 1 Minute")
|
||||
updateInterval = 1
|
||||
}
|
||||
|
||||
db, err := sql.Open("mysql", dbDSN)
|
||||
if err != nil {
|
||||
log.Fatal("Fehler beim Verbinden mit der Datenbank: ", err)
|
||||
|
@ -85,9 +91,13 @@ func main() {
|
|||
defer db.Close()
|
||||
|
||||
ticker := time.NewTicker(5 * time.Minute)
|
||||
updateTicker := time.NewTicker(time.Duration(updateInterval) * time.Minute)
|
||||
defer ticker.Stop()
|
||||
defer updateTicker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-updateTicker.C:
|
||||
for _, stationID := range stationIDs {
|
||||
departures := fetchDepartures(apiBaseURL, stationID, duration)
|
||||
for _, dep := range departures {
|
||||
|
@ -95,15 +105,9 @@ func main() {
|
|||
}
|
||||
}
|
||||
deleteOldEntries(db, deleteAfter)
|
||||
|
||||
select {
|
||||
case <-ticker.C:
|
||||
logDatabaseStats(db)
|
||||
default:
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Minute)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue