Idle mode
This commit is contained in:
parent
f7ad59b107
commit
79473280dd
@ -1,4 +1,5 @@
|
||||
{
|
||||
"last_access": 5,
|
||||
"page": "http://phoenix-f.opendmr.net/ipsc/_monitor.html",
|
||||
"reload": 3,
|
||||
"users": "https://radioid.net/static/users.json",
|
||||
|
14
main.go
14
main.go
@ -16,6 +16,7 @@ import (
|
||||
/* Store the calls locally */
|
||||
var (
|
||||
calls []Call
|
||||
last_access time.Time
|
||||
mu sync.Mutex
|
||||
uptime time.Time
|
||||
stats Stats
|
||||
@ -61,6 +62,7 @@ type Users struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Last_access time.Duration `json:"last_access"`
|
||||
Page string `json:"page"`
|
||||
Reload int64 `json:"reload"`
|
||||
Users string `json:"users"`
|
||||
@ -113,6 +115,7 @@ func req(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
mu.Lock()
|
||||
stats.Hits++
|
||||
last_access = time.Now()
|
||||
json.NewEncoder(w).Encode(calls)
|
||||
mu.Unlock()
|
||||
}
|
||||
@ -167,6 +170,7 @@ func main() {
|
||||
}
|
||||
|
||||
callback := make(chan []Call)
|
||||
last_access = time.Now()
|
||||
last_update := time.Now()
|
||||
uptime = time.Now()
|
||||
user_update = time.Now()
|
||||
@ -175,7 +179,14 @@ func main() {
|
||||
go serv()
|
||||
|
||||
for {
|
||||
if time.Since(last_update) > time.Second*time.Duration(config.Reload) {
|
||||
time.Sleep(time.Millisecond * 256)
|
||||
|
||||
/* If we're idle don't scrape */
|
||||
if time.Since(last_access) >= time.Minute*config.Last_access {
|
||||
continue
|
||||
}
|
||||
|
||||
if time.Since(last_update) >= time.Second*time.Duration(config.Reload) {
|
||||
last_update = time.Now()
|
||||
go scrape(&config, callback)
|
||||
mu.Lock()
|
||||
@ -183,6 +194,5 @@ func main() {
|
||||
calls = <-callback
|
||||
mu.Unlock()
|
||||
}
|
||||
time.Sleep(time.Millisecond * 256)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user