Skip to content

Commit

Permalink
Always return a name even when there is an error
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
alexellis committed Jul 14, 2021
1 parent 124ae95 commit aa14f05
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions types/cron_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit aa14f05

Please sign in to comment.