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",
|
"page": "http://phoenix-f.opendmr.net/ipsc/_monitor.html",
|
||||||
"reload": 3,
|
"reload": 3,
|
||||||
"users": "https://radioid.net/static/users.json",
|
"users": "https://radioid.net/static/users.json",
|
||||||
|
22
main.go
22
main.go
@ -16,6 +16,7 @@ import (
|
|||||||
/* Store the calls locally */
|
/* Store the calls locally */
|
||||||
var (
|
var (
|
||||||
calls []Call
|
calls []Call
|
||||||
|
last_access time.Time
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
uptime time.Time
|
uptime time.Time
|
||||||
stats Stats
|
stats Stats
|
||||||
@ -61,10 +62,11 @@ type Users struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Page string `json:"page"`
|
Last_access time.Duration `json:"last_access"`
|
||||||
Reload int64 `json:"reload"`
|
Page string `json:"page"`
|
||||||
Users string `json:"users"`
|
Reload int64 `json:"reload"`
|
||||||
Users_reload int64 `json:"users_reload"`
|
Users string `json:"users"`
|
||||||
|
Users_reload int64 `json:"users_reload"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pull data from radioid.net user dump */
|
/* Pull data from radioid.net user dump */
|
||||||
@ -113,6 +115,7 @@ func req(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
stats.Hits++
|
stats.Hits++
|
||||||
|
last_access = time.Now()
|
||||||
json.NewEncoder(w).Encode(calls)
|
json.NewEncoder(w).Encode(calls)
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
@ -167,6 +170,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
callback := make(chan []Call)
|
callback := make(chan []Call)
|
||||||
|
last_access = time.Now()
|
||||||
last_update := time.Now()
|
last_update := time.Now()
|
||||||
uptime = time.Now()
|
uptime = time.Now()
|
||||||
user_update = time.Now()
|
user_update = time.Now()
|
||||||
@ -175,7 +179,14 @@ func main() {
|
|||||||
go serv()
|
go serv()
|
||||||
|
|
||||||
for {
|
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()
|
last_update = time.Now()
|
||||||
go scrape(&config, callback)
|
go scrape(&config, callback)
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
@ -183,6 +194,5 @@ func main() {
|
|||||||
calls = <-callback
|
calls = <-callback
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
time.Sleep(time.Millisecond * 256)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user