Add debug vars
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2019-03-24 13:55:46 +01:00
parent dc557efde9
commit 6d51145dad
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"expvar"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -49,6 +50,22 @@ type Feed struct {
ResubscribeAt int64 `redis:"resubscribe_at"` ResubscribeAt int64 `redis:"resubscribe_at"`
} }
var (
subscribeRuns *expvar.Int
resubscriptions *expvar.Int
resubscribeErrors *expvar.Int
)
func init() {
subscribeRuns = expvar.NewInt("subscribe.runs")
resubscriptions = expvar.NewInt("subscribe.calls")
resubscribeErrors = expvar.NewInt("subscribe.errors")
expvar.Publish("subscribe.runs", subscribeRuns)
expvar.Publish("subscribe.calls", resubscriptions)
expvar.Publish("subscribe.errors", resubscribeErrors)
}
func (h *hubIncomingBackend) GetSecret(id int64) string { func (h *hubIncomingBackend) GetSecret(id int64) string {
conn := h.pool.Get() conn := h.pool.Get()
defer conn.Close() defer conn.Close()
@ -231,7 +248,12 @@ func (h *hubIncomingBackend) run() error {
select { select {
case <-ticker.C: case <-ticker.C:
log.Println("Getting feeds for WebSub") log.Println("Getting feeds for WebSub")
feeds := h.GetFeeds() subscribeRuns.Add(1)
feeds, err := h.Feeds()
if err != nil {
}
for _, feed := range feeds { for _, feed := range feeds {
log.Printf("Looking at %s\n", feed.URL) log.Printf("Looking at %s\n", feed.URL)
if feed.ResubscribeAt == 0 || time.Now().After(time.Unix(feed.ResubscribeAt, 0)) { if feed.ResubscribeAt == 0 || time.Now().After(time.Unix(feed.ResubscribeAt, 0)) {
@ -239,9 +261,11 @@ func (h *hubIncomingBackend) run() error {
feed.Callback = fmt.Sprintf("%s/incoming/%d", h.baseURL, feed.ID) feed.Callback = fmt.Sprintf("%s/incoming/%d", h.baseURL, feed.ID)
} }
log.Printf("Send resubscribe for %q on %q with callback %q\n", feed.URL, feed.Hub, feed.Callback) log.Printf("Send resubscribe for %q on %q with callback %q\n", feed.URL, feed.Hub, feed.Callback)
resubscriptions.Add(1)
err := h.Subscribe(&feed) err := h.Subscribe(&feed)
if err != nil { if err != nil {
log.Printf("Error while subscribing: %s", err) log.Printf("Error while subscribing: %s", err)
resubscribeErrors.Add(1)
} }
} }
} }