func checkForUpdates() { checkTicker := time.Tick(checkFrequency) for range checkTicker { log.Println("Checking for updates..") update, err := cr.GetUpdate(instanceID, appID, groupID, currentVersion) if err != nil { log.Printf("\t- No updates (error: %v)\n", err) continue } log.Println("\t- Updates available!") log.Println("\t- Downloading update package..") cr.EventDownloadStarted(instanceID, appID, groupID) downloadPackage(update.URL, update.Filename) log.Println("\t- Update package downloaded") cr.EventDownloadFinished(instanceID, appID, groupID) log.Println("\t- Update completed successfully :)") cr.EventUpdateSucceeded(instanceID, appID, groupID) log.Println("\t- Restarting server using new package") syscall.Kill(syscall.Getpid(), syscall.SIGUSR2) break } }
func (u *Updater) Start() { t := time.Tick(u.checkFrequency) for range t { update, err := cr.GetUpdate(u.a.InstanceID, u.a.AppID, u.a.GroupID, u.a.Version) switch err { case nil: case cr.ErrNoUpdate: logger.Debug("no update from CoreRoller") continue default: logger.Warn("Getting update from CoreRoller", "appID", u.a.AppID, "groupID", u.a.GroupID, "instanceID", u.a.InstanceID, "error", err.Error()) continue } logger.Info("got update from coreroller", "version", update.Version) if err := u.processUpdate(update); err != nil { cr.EventUpdateFailed(u.a.InstanceID, u.a.AppID, u.a.GroupID) continue } break } }