Skip to content

Commit 124ae95

Browse files
committed
Remove debug line for invocations
This showed the URL which is no longer required Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent dca4fa1 commit 124ae95

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

main.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const topic = "cron-function"
2525
func main() {
2626
config, err := getControllerConfig()
2727
if err != nil {
28-
panic(err)
28+
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
29+
os.Exit(1)
2930
}
3031

3132
sha, ver := version.GetReleaseInfo()
@@ -38,14 +39,26 @@ func main() {
3839
config.ContentType,
3940
config.PrintResponse)
4041

42+
go func() {
43+
for {
44+
r := <-invoker.Responses
45+
if r.Error != nil {
46+
log.Printf("Error with: %s, %s", r.Function, err.Error())
47+
} else {
48+
log.Printf("Response: %s [%d]", r.Function, r.Status)
49+
}
50+
}
51+
}()
52+
4153
cronScheduler := cfunction.NewScheduler()
4254
interval := time.Second * 10
4355

4456
cronScheduler.Start()
4557
err = startFunctionProbe(interval, topic, config, cronScheduler, invoker)
4658

4759
if err != nil {
48-
panic(err)
60+
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
61+
os.Exit(1)
4962
}
5063
}
5164

types/cron_function.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,32 @@ func (c *CronFunctions) Contains(cf *CronFunction) bool {
5050
// and returns error if it is not possible
5151
func ToCronFunction(f ptypes.FunctionStatus, namespace string, topic string) (CronFunction, error) {
5252
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)
5454
}
55+
5556
fTopic := (*f.Annotations)["topic"]
5657
fSchedule := (*f.Annotations)["schedule"]
5758

5859
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)
6061
}
6162

6263
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)
6465
}
6566

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
7273
}
7374

7475
// InvokeFunction Invokes the cron function
7576
func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
7677

7778
gwURL := fmt.Sprintf("%s/%s", i.GatewayURL, c.String())
78-
log.Printf("HTTP POST: %s", gwURL)
7979

8080
req, err := http.NewRequest(http.MethodPost, gwURL, nil)
8181
if err != nil {
@@ -91,7 +91,7 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
9191

9292
if err != nil {
9393
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())),
9595
}
9696
return nil, err
9797
}
@@ -103,8 +103,9 @@ func (c CronFunction) InvokeFunction(i *types.Invoker) (*[]byte, error) {
103103
if err != nil {
104104
log.Printf("Error reading body")
105105
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())),
107107
}
108+
108109
return nil, err
109110
}
110111

types/scheduler.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ type ScheduledFunction struct {
3535
// ScheduledFunctions is an array of ScheduledFunction
3636
type ScheduledFunctions []ScheduledFunction
3737

38-
// AddCronFunction adds a function to cron
39-
func (s *Scheduler) AddCronFunction(c CronFunction, invoker *types.Invoker) (ScheduledFunction, error) {
40-
eID, err := s.main.AddFunc(c.Schedule, func() {
41-
log.Printf("Executing function: %s", c.String())
42-
c.InvokeFunction(invoker)
43-
})
44-
return ScheduledFunction{c, EntryID(eID)}, err
45-
}
46-
4738
// NewScheduler returns a scheduler
4839
func NewScheduler() *Scheduler {
4940
return &Scheduler{
@@ -56,6 +47,15 @@ func (s *Scheduler) Start() {
5647
s.main.Start()
5748
}
5849

50+
// AddCronFunction adds a function to cron
51+
func (s *Scheduler) AddCronFunction(c CronFunction, invoker *types.Invoker) (ScheduledFunction, error) {
52+
eID, err := s.main.AddFunc(c.Schedule, func() {
53+
log.Printf("Executing function: %s", c.String())
54+
c.InvokeFunction(invoker)
55+
})
56+
return ScheduledFunction{c, EntryID(eID)}, err
57+
}
58+
5959
// Remove removes the function from scheduler
6060
func (s *Scheduler) Remove(function ScheduledFunction) {
6161
s.main.Remove(cron.EntryID(function.ID))

0 commit comments

Comments
 (0)