Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
	"github.com/concourse/autopilot/rewind"
)

var _ = Describe("Rewind", func() {
	It("runs through all actions if they're all successful", func() {
		firstRun := false
		secondRun := false

		actions := rewind.Actions{
			Actions: []rewind.Action{
				{
					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())
	})