@@ -110,6 +110,15 @@ func (s Calls) AwaitAll() map[*Call]error {
110110 return errs
111111}
112112
113+ func (c * Call ) callableMetric (name string ) monitoring.Metric {
114+ metric := monitoring .NewMetric (name )
115+ metric .AddTag ("runtype" , c .getRunTypeTag ())
116+ metric .AddTag ("name" , c .GetName ())
117+ metric .AddTag ("trigger" , c .GetTraits ().Trigger )
118+ metric .AddTag ("envId" , c .parentRole .GetEnvironmentId ().String ())
119+ return metric
120+ }
121+
113122func (c * Call ) Call () error {
114123 log .WithField ("trigger" , c .Traits .Trigger ).
115124 WithField ("await" , c .Traits .Await ).
@@ -178,6 +187,7 @@ func (c *Call) Call() error {
178187 EnvironmentId : c .parentRole .GetEnvironmentId ().String (),
179188 })
180189
190+ metric .AddResult (monitoring .ERROR )
181191 return err
182192 }
183193 if len (returnVar ) > 0 {
@@ -206,6 +216,7 @@ func (c *Call) Call() error {
206216 EnvironmentId : c .parentRole .GetEnvironmentId ().String (),
207217 })
208218
219+ metric .AddResult (monitoring .ERROR )
209220 return errors .New (errMsg )
210221 }
211222
@@ -224,18 +235,10 @@ func (c *Call) Call() error {
224235 EnvironmentId : c .parentRole .GetEnvironmentId ().String (),
225236 })
226237
238+ metric .AddResult (monitoring .SUCCESS )
227239 return nil
228240}
229241
230- func (c * Call ) callableMetric (name string ) monitoring.Metric {
231- metric := monitoring .NewMetric (name )
232- metric .AddTag ("runtype" , c .getRunTypeTag ())
233- metric .AddTag ("name" , c .GetName ())
234- metric .AddTag ("trigger" , c .GetTraits ().Trigger )
235- metric .AddTag ("envId" , c .parentRole .GetEnvironmentId ().String ())
236- return metric
237- }
238-
239242func (c * Call ) Start () {
240243 c .await = make (chan error )
241244 ctx , cancel := context .WithCancel (context .Background ())
@@ -247,9 +250,16 @@ func (c *Call) Start() {
247250 callId := fmt .Sprintf ("hook:%s:%s" , c .GetTraits ().Trigger , c .GetName ())
248251 log .Debugf ("%s started" , callId )
249252 defer utils .TimeTrack (time .Now (), callId , log .WithPrefix ("callable" ))
253+ err := c .Call ()
250254 select {
251- case c .await <- c .Call ():
255+ case c .await <- err :
256+ if err == nil {
257+ metric .AddResult (monitoring .SUCCESS )
258+ } else {
259+ metric .AddResult (monitoring .ERROR )
260+ }
252261 case <- ctx .Done ():
262+ metric .AddResult (monitoring .CANCELLED )
253263 log .Debugf ("%s cancelled" , callId )
254264 }
255265 close (c .await )
0 commit comments