Commit 865d668c authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Fix error handling on fetch

parent 8779366e
...@@ -100,15 +100,11 @@ func (c *config) taskServices(t task) (services []service, err error) { ...@@ -100,15 +100,11 @@ func (c *config) taskServices(t task) (services []service, err error) {
} }
} }
// try the group based services for _, groupServices := range c.GroupToServices {
// TODO is this desired? for _, groupService := range groupServices {
if len(services) == 0 { if groupService.Name == t.RoutingKey {
for _, groupServices := range c.GroupToServices { services = []service{groupService}
for _, groupService := range groupServices { return
if groupService.Name == t.RoutingKey {
services = []service{groupService}
return
}
} }
} }
} }
...@@ -118,9 +114,9 @@ func (c *config) taskServices(t task) (services []service, err error) { ...@@ -118,9 +114,9 @@ func (c *config) taskServices(t task) (services []service, err error) {
services, ok = c.GroupToServices[t.RoutingKey] services, ok = c.GroupToServices[t.RoutingKey]
if !ok { if !ok {
err = fmt.Errorf( err = fmt.Errorf(
"Group %s has no mapped services! Unable to get service for task %s", "%s: Group %s has no mapped services",
t.RoutingKey,
t, t,
t.RoutingKey,
) )
return return
} }
...@@ -140,18 +136,16 @@ func (c *config) taskFetcher() { ...@@ -140,18 +136,16 @@ func (c *config) taskFetcher() {
// start ticker // start ticker
ticker := time.NewTicker(c.FetchInterval) ticker := time.NewTicker(c.FetchInterval)
go func() { for {
for { go func() {
go func() { if err := c.fetchTasks(); err != nil {
if err := c.fetchTasks(); err != nil { log.Printf("[Fetch] error fetching: %s", err)
log.Printf("[Fetch] error fetching: %s", err) }
} }()
}()
// wait for a tick // wait for a tick
<-ticker.C <-ticker.C
} }
}()
} }
// handles tasks in c.NewTasks // handles tasks in c.NewTasks
...@@ -253,7 +247,10 @@ func (c *config) fetchTasks() (err error) { ...@@ -253,7 +247,10 @@ func (c *config) fetchTasks() (err error) {
for _, task := range newTasks { for _, task := range newTasks {
err = c.scheduleTask(task) err = c.scheduleTask(task)
if err != nil { if err != nil {
return log.Printf("[Fetch] %v", err)
// we execute all tasks even when one fails
err = nil
} }
} }
return return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment