func (plugin AutopilotPlugin) Run(cliConnection plugin.CliConnection, args []string) { appRepo := NewApplicationRepo(cliConnection) appName, manifestPath, appPath, err := ParseArgs(args) fatalIf(err) venerableAppName := appName + "-venerable" actions := rewind.Actions{ Actions: []rewind.Action{ // rename { Forward: func() error { return appRepo.RenameApplication(appName, venerableAppName) }, }, // push { Forward: func() error { return appRepo.PushApplication(manifestPath, appPath) }, ReversePrevious: func() error { return appRepo.RenameApplication(venerableAppName, appName) }, }, // delete { Forward: func() error { return appRepo.DeleteApplication(venerableAppName) }, }, }, RewindFailureMessage: "Oh no. Something's gone wrong. I've tried to roll back but you should check to see if everything is OK.", } err = actions.Execute() fatalIf(err) fmt.Println() fmt.Println("A new version of your application has successfully been pushed!") fmt.Println() err = appRepo.ListApplications() fatalIf(err) }
{ Forward: func() error { firstRun = true return nil }, }, { Forward: func() error { secondRun = true return nil }, }, }, } err := actions.Execute() Ω(err).ShouldNot(HaveOccurred()) Ω(firstRun).Should(BeTrue()) Ω(secondRun).Should(BeTrue()) }) It("stops and runs the rewind of an action if it fails", func() { firstRun := false secondRun := false secondReverseRun := false thirdRun := false actions := rewind.Actions{ Actions: []rewind.Action{ {