Browse Source

Add info to timers

DarthSim 7 years ago
parent
commit
f569067588
2 changed files with 6 additions and 5 deletions
  1. 2 2
      server.go
  2. 4 3
      timer.go

+ 2 - 2
server.go

@@ -142,7 +142,7 @@ func checkSecret(s string) bool {
 }
 }
 
 
 func (h *httpHandler) lock() {
 func (h *httpHandler) lock() {
-	t := startTimer(time.Duration(conf.WaitTimeout) * time.Second)
+	t := startTimer(time.Duration(conf.WaitTimeout)*time.Second, "Waiting")
 
 
 	select {
 	select {
 	case h.sem <- struct{}{}:
 	case h.sem <- struct{}{}:
@@ -173,7 +173,7 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 		panic(invalidSecretErr)
 		panic(invalidSecretErr)
 	}
 	}
 
 
-	t := startTimer(time.Duration(conf.WriteTimeout) * time.Second)
+	t := startTimer(time.Duration(conf.WriteTimeout)*time.Second, "Processing")
 
 
 	h.lock()
 	h.lock()
 	defer h.unlock()
 	defer h.unlock()

+ 4 - 3
timer.go

@@ -8,10 +8,11 @@ import (
 type timer struct {
 type timer struct {
 	StartTime time.Time
 	StartTime time.Time
 	Timer     <-chan time.Time
 	Timer     <-chan time.Time
+	Info      string
 }
 }
 
 
-func startTimer(dt time.Duration) *timer {
-	return &timer{time.Now(), time.After(dt)}
+func startTimer(dt time.Duration, info string) *timer {
+	return &timer{time.Now(), time.After(dt), info}
 }
 }
 
 
 func (t *timer) Check() {
 func (t *timer) Check() {
@@ -24,7 +25,7 @@ func (t *timer) Check() {
 }
 }
 
 
 func (t *timer) TimeoutErr() imgproxyError {
 func (t *timer) TimeoutErr() imgproxyError {
-	return newError(503, fmt.Sprintf("Timeout after %v", t.Since()), "Timeout")
+	return newError(503, fmt.Sprintf("Timeout after %v (%s)", t.Since(), t.Info), "Timeout")
 }
 }
 
 
 func (t *timer) Since() time.Duration {
 func (t *timer) Since() time.Duration {