@@ -50,32 +50,32 @@ func (c *CronFunctions) Contains(cf *CronFunction) bool {
50
50
// and returns error if it is not possible
51
51
func ToCronFunction (f ptypes.FunctionStatus , namespace string , topic string ) (CronFunction , error ) {
52
52
if f .Annotations == nil {
53
- return CronFunction {}, errors . New ( fmt .Sprint ( f . Name , " has no annotations." ) )
53
+ return CronFunction {}, fmt .Errorf ( "%s has no annotations" , f . Name )
54
54
}
55
+
55
56
fTopic := (* f .Annotations )["topic" ]
56
57
fSchedule := (* f .Annotations )["schedule" ]
57
58
58
59
if fTopic != topic {
59
- return CronFunction {}, errors . New ( fmt .Sprint ( f . Name , " has wrong topic: " , fTopic ) )
60
+ return CronFunction {}, fmt .Errorf ( "%s has wrong topic: %s " , fTopic , f . Name )
60
61
}
61
62
62
63
if ! CheckSchedule (fSchedule ) {
63
- return CronFunction {}, errors . New ( fmt .Sprint ( f . Name , " has wrong cron schedule: " , fSchedule ) )
64
+ return CronFunction {}, fmt .Errorf ( "%s has wrong cron schedule: %s " , f . Name , fSchedule )
64
65
}
65
66
66
- var c CronFunction
67
- c . FuncData = f
68
- c . Name = f .Name
69
- c . Namespace = namespace
70
- c . Schedule = fSchedule
71
- return c , nil
67
+ return CronFunction {
68
+ FuncData : f ,
69
+ Name : f .Name ,
70
+ Namespace : namespace ,
71
+ Schedule : fSchedule ,
72
+ } , nil
72
73
}
73
74
74
75
// InvokeFunction Invokes the cron function
75
76
func (c CronFunction ) InvokeFunction (i * types.Invoker ) (* []byte , error ) {
76
77
77
78
gwURL := fmt .Sprintf ("%s/%s" , i .GatewayURL , c .String ())
78
- log .Printf ("HTTP POST: %s" , gwURL )
79
79
80
80
req , err := http .NewRequest (http .MethodPost , gwURL , nil )
81
81
if err != nil {
@@ -91,7 +91,7 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
91
91
92
92
if err != nil {
93
93
i .Responses <- types.InvokerResponse {
94
- Error : errors .Wrap (err , fmt .Sprint ("unable to invoke " , c .Name , " in " , c . Namespace )),
94
+ Error : errors .Wrap (err , fmt .Sprintf ("unable to invoke %s " , c .String () )),
95
95
}
96
96
return nil , err
97
97
}
@@ -103,8 +103,9 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
103
103
if err != nil {
104
104
log .Printf ("Error reading body" )
105
105
i .Responses <- types.InvokerResponse {
106
- Error : errors .Wrap (err , fmt .Sprint ("unable to invoke " , c .Name , " in " , c . Namespace )),
106
+ Error : errors .Wrap (err , fmt .Sprintf ("unable to invoke %s " , c .String () )),
107
107
}
108
+
108
109
return nil , err
109
110
}
110
111
0 commit comments