Skip to content

Commit

Permalink
worker now defers postCommand so that it runs if preCommand fails and…
Browse files Browse the repository at this point in the history
… restarts the old service
  • Loading branch information
ChrisMcKenzie committed Nov 4, 2015
1 parent e6159da commit c701162
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions service/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (w *Dispatcher) Work() {
res, err := executeCommand(w.config.PreCommand)
if err != nil {
log.Printf("[ERR]: Unable to execute preComment. %v", err)
return
}
log.Printf("[INF]: preCommand executed successfully. %v", res)
}
Expand All @@ -115,11 +116,13 @@ func (w *Dispatcher) Work() {
}

if w.config.PostCommand != "" {
res, err := executeCommand(w.config.PostCommand)
if err != nil {
log.Printf("[ERR]: Unable to execute postCommand. %v", err)
}
log.Printf("[INF]: postCommand executed successfully. %v", res)
defer func() {
res, err := executeCommand(w.config.PostCommand)
if err != nil {
log.Printf("[ERR]: Unable to execute postCommand. %v", err)
}
log.Printf("[INF]: postCommand executed successfully. %v", res)
}()
}

log.Printf("[INF]: Update for %s installed successfully. [hash: %s] [files written: %d]", w.config.Name, meta.Hash, filesWritten)
Expand Down

0 comments on commit c701162

Please sign in to comment.