fix(speed): Increase query speed
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
699d2721f2
commit
1a013939f5
@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
var apiClient *api.Client
|
||||
var alert = 0
|
||||
|
||||
// Init will initialize telegram bot.
|
||||
func Init(alertChan chan api.Availability) {
|
||||
@ -32,11 +33,23 @@ func Init(alertChan chan api.Availability) {
|
||||
}
|
||||
|
||||
// define an interval and the ticker for this interval
|
||||
interval := time.Duration(15) * time.Second
|
||||
interval := time.Duration(5) * time.Second
|
||||
// create a new Ticker
|
||||
tk := time.NewTicker(interval)
|
||||
|
||||
resetAlert := 0
|
||||
for range tk.C {
|
||||
if alert > 10 {
|
||||
alert = 0
|
||||
resetAlert = 10
|
||||
continue
|
||||
}
|
||||
|
||||
if resetAlert != 0 {
|
||||
resetAlert--
|
||||
continue
|
||||
}
|
||||
|
||||
checkPrice(alertChan)
|
||||
}
|
||||
}
|
||||
@ -56,5 +69,6 @@ func checkPrice(alertChan chan api.Availability) {
|
||||
if availabilities.Results[0].Price < PriceAlert {
|
||||
log.Info("Launching an alert !")
|
||||
alertChan <- availabilities.Results[0]
|
||||
alert++
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user