From aa14f05b4e3d2c771d631671523736886aeaa66c Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Wed, 14 Jul 2021 13:04:40 +0100 Subject: [PATCH] Always return a name even when there is an error Prior to the change, there was no way to associate an error with a function being called or a topic. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- types/cron_function.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/types/cron_function.go b/types/cron_function.go index 5392b37..fafd25f 100644 --- a/types/cron_function.go +++ b/types/cron_function.go @@ -75,6 +75,9 @@ func ToCronFunction(f ptypes.FunctionStatus, namespace string, topic string) (Cr // InvokeFunction Invokes the cron function func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) { + name := c.Name + topic := (*c.FuncData.Annotations)["topic"] + gwURL := fmt.Sprintf("%s/%s", i.GatewayURL, c.String()) req, err := http.NewRequest(http.MethodPost, gwURL, nil) @@ -91,7 +94,10 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) { if err != nil { i.Responses <- types.InvokerResponse{ - Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())), + Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())), + Function: name, + Topic: topic, + Status: http.StatusServiceUnavailable, } return nil, err } @@ -103,7 +109,10 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) { if err != nil { log.Printf("Error reading body") i.Responses <- types.InvokerResponse{ - Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())), + Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())), + Status: http.StatusServiceUnavailable, + Function: name, + Topic: topic, } return nil, err @@ -116,8 +125,8 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) { Body: body, Status: res.StatusCode, Header: &res.Header, - Function: c.Name, - Topic: (*c.FuncData.Annotations)["topic"], + Function: name, + Topic: topic, } return body, nil