@@ -21,6 +21,7 @@ package trigger
2121import (
2222 "fmt"
2323 "io"
24+ "math"
2425 "net/http"
2526 "os"
2627 "strings"
@@ -51,6 +52,12 @@ func NewHTTPAction(intervalStr string, times int, url, method, body string, head
5152 return nil , fmt .Errorf ("trigger interval should be > 0, but was %s" , interval )
5253 }
5354
55+ if times <= 0 {
56+ logger .Log .Warnf ("trigger times (%d) is invalid (<=0). It has been set to a large number (%d) to simulate infinite runs. " +
57+ "consider using a positive value." , times , math .MaxInt32 )
58+ times = math .MaxInt32
59+ }
60+
5461 // there can be env variables in url, say, "http://${GATEWAY_HOST}:${GATEWAY_PORT}/test"
5562 url = os .ExpandEnv (url )
5663
@@ -70,7 +77,13 @@ func NewHTTPAction(intervalStr string, times int, url, method, body string, head
7077func (h * httpAction ) Do () chan error {
7178 t := time .NewTicker (h .interval )
7279
73- logger .Log .Infof ("trigger will request URL %s %d times with interval %s." , h .url , h .times , h .interval )
80+ var timesInfo string
81+ if h .times == math .MaxInt32 {
82+ timesInfo = "a very large number of times (practically until stopped)"
83+ } else {
84+ timesInfo = fmt .Sprintf ("%d times" , h .times )
85+ }
86+ logger .Log .Infof ("trigger will request URL %s %s with interval %s." , h .url , timesInfo , h .interval )
7487
7588 result := make (chan error )
7689 sent := false
@@ -87,10 +100,12 @@ func (h *httpAction) Do() chan error {
87100 result <- err
88101 sent = true
89102 }
90- if h .times == h .executedCount {
103+ if h .times != math .MaxInt32 && h .executedCount >= h .times {
104+ logger .Log .Infof ("trigger has completed %d requests and will stop." , h .executedCount )
91105 return
92106 }
93107 case <- h .stopCh :
108+ logger .Log .Infof ("trigger was stopped manually after %d executions." , h .executedCount )
94109 return
95110 }
96111 }
0 commit comments