Skip to content

Commit aa14f05

Browse files
committed
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) <[email protected]>
1 parent 124ae95 commit aa14f05

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

types/cron_function.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func ToCronFunction(f ptypes.FunctionStatus, namespace string, topic string) (Cr
7575
// InvokeFunction Invokes the cron function
7676
func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
7777

78+
name := c.Name
79+
topic := (*c.FuncData.Annotations)["topic"]
80+
7881
gwURL := fmt.Sprintf("%s/%s", i.GatewayURL, c.String())
7982

8083
req, err := http.NewRequest(http.MethodPost, gwURL, nil)
@@ -91,7 +94,10 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
9194

9295
if err != nil {
9396
i.Responses <- types.InvokerResponse{
94-
Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())),
97+
Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())),
98+
Function: name,
99+
Topic: topic,
100+
Status: http.StatusServiceUnavailable,
95101
}
96102
return nil, err
97103
}
@@ -103,7 +109,10 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
103109
if err != nil {
104110
log.Printf("Error reading body")
105111
i.Responses <- types.InvokerResponse{
106-
Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())),
112+
Error: errors.Wrap(err, fmt.Sprintf("unable to invoke %s", c.String())),
113+
Status: http.StatusServiceUnavailable,
114+
Function: name,
115+
Topic: topic,
107116
}
108117

109118
return nil, err
@@ -116,8 +125,8 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
116125
Body: body,
117126
Status: res.StatusCode,
118127
Header: &res.Header,
119-
Function: c.Name,
120-
Topic: (*c.FuncData.Annotations)["topic"],
128+
Function: name,
129+
Topic: topic,
121130
}
122131

123132
return body, nil

0 commit comments

Comments
 (0)