@@ -101,6 +101,16 @@ func formatInitDuration(initStart time.Time, initEnd time.Time, timeoutDuration
101101 float64 (timeoutDuration .Nanoseconds ())) / float64 (time .Millisecond )
102102 return fmt .Sprintf ("Init Duration: %.2f ms\t " , initTimeMS )
103103}
104+
105+ func printInvokeReport (sandbox Sandbox , invokeID string , initStart time.Time , invokeStart time.Time , memorySize string , timeoutDuration time.Duration ) {
106+ initEnd := sandbox .AwaitInitCompletion ()
107+ initDuration := formatInitDuration (initStart , initEnd , timeoutDuration )
108+ if ! initStart .IsZero () && initEnd .After (invokeStart ) {
109+ invokeStart = initEnd
110+ }
111+ printEndReports (invokeID , initDuration , memorySize , invokeStart , timeoutDuration )
112+ }
113+
104114func InvokeHandler (w http.ResponseWriter , r * http.Request , sandbox Sandbox , bs interop.Bootstrap ) {
105115 log .Debugf ("invoke: -> %s %s %v" , r .Method , r .URL , r .Header )
106116 bodyBytes , err := ioutil .ReadAll (r .Body )
@@ -211,12 +221,7 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox, bs i
211221 w .WriteHeader (http .StatusGatewayTimeout )
212222 return
213223 case rapidcore .ErrInvokeTimeout :
214- initEnd := sandbox .AwaitInitCompletion ()
215- initDuration := formatInitDuration (initStart , initEnd , timeoutDuration )
216- if ! initStart .IsZero () && initEnd .After (invokeStart ) {
217- invokeStart = initEnd
218- }
219- printEndReports (invokePayload .ID , initDuration , memorySize , invokeStart , timeoutDuration )
224+ printInvokeReport (sandbox , invokePayload .ID , initStart , invokeStart , memorySize , timeoutDuration )
220225
221226 w .Write ([]byte (fmt .Sprintf ("Task timed out after %d.00 seconds" , timeout )))
222227 time .Sleep (100 * time .Millisecond )
@@ -225,12 +230,7 @@ func InvokeHandler(w http.ResponseWriter, r *http.Request, sandbox Sandbox, bs i
225230 }
226231 }
227232
228- initEnd := sandbox .AwaitInitCompletion ()
229- initDuration := formatInitDuration (initStart , initEnd , timeoutDuration )
230- if ! initStart .IsZero () && initEnd .After (invokeStart ) {
231- invokeStart = initEnd
232- }
233- printEndReports (invokePayload .ID , initDuration , memorySize , invokeStart , timeoutDuration )
233+ printInvokeReport (sandbox , invokePayload .ID , initStart , invokeStart , memorySize , timeoutDuration )
234234
235235 if invokeResp .StatusCode != 0 {
236236 w .WriteHeader (invokeResp .StatusCode )
0 commit comments