浏览代码

Add info to timers

DarthSim 7 年之前
父节点
当前提交
f569067588
共有 2 个文件被更改,包括 6 次插入5 次删除
  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() {
-	t := startTimer(time.Duration(conf.WaitTimeout) * time.Second)
+	t := startTimer(time.Duration(conf.WaitTimeout)*time.Second, "Waiting")
 
 	select {
 	case h.sem <- struct{}{}:
@@ -173,7 +173,7 @@ func (h *httpHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 		panic(invalidSecretErr)
 	}
 
-	t := startTimer(time.Duration(conf.WriteTimeout) * time.Second)
+	t := startTimer(time.Duration(conf.WriteTimeout)*time.Second, "Processing")
 
 	h.lock()
 	defer h.unlock()

+ 4 - 3
timer.go

@@ -8,10 +8,11 @@ import (
 type timer struct {
 	StartTime 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() {
@@ -24,7 +25,7 @@ func (t *timer) Check() {
 }
 
 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 {