Revert "working with opt-in"

This reverts commit 4068ffdaf541354e75507add7ca0b193993fcd52.
This commit is contained in:
Matthew Hooker 2018-01-22 15:08:10 -08:00
parent e98f201602
commit a0c625ea44
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
4 changed files with 13 additions and 17 deletions

View File

@ -37,10 +37,6 @@ type StepRunSourceInstance struct {
}
func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepAction {
return s.RunWithContext(context.Background(), state)
}
func (s *StepRunSourceInstance) RunWithContext(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2)
var keyName string
if name, ok := state.GetOk("keyPair"); ok {
@ -183,6 +179,15 @@ func (s *StepRunSourceInstance) RunWithContext(ctx context.Context, state multis
describeInstance := &ec2.DescribeInstancesInput{
InstanceIds: []*string{aws.String(instanceId)},
}
ctx, cancel := context.WithCancel(context.Background())
go func() {
for {
if _, ok := state.GetOk(multistep.StateCancelled); ok {
cancel()
}
}
}()
if err := ec2conn.WaitUntilInstanceRunningWithContext(ctx, describeInstance); err != nil {
err := fmt.Errorf("Error waiting for instance (%s) to become ready: %s", instanceId, err)

View File

@ -70,13 +70,7 @@ func (b *BasicRunner) Run(state StateBag) {
break
}
var action StepAction
if stepCtx, ok := step.(StepRunnableWithContext); ok {
action = stepCtx.RunWithContext(ctx, state)
} else {
action = step.Run(state)
}
action := step.Run(ctx, state)
defer step.Cleanup(state)
if _, ok := state.GetOk(StateCancelled); ok {

View File

@ -1,6 +1,7 @@
package multistep
import (
"context"
"fmt"
"reflect"
"sync"
@ -113,7 +114,7 @@ type debugStepPause struct {
PauseFn DebugPauseFn
}
func (s *debugStepPause) Run(state StateBag) StepAction {
func (s *debugStepPause) Run(_ context.Context, state StateBag) StepAction {
s.PauseFn(DebugLocationAfterRun, s.StepName, state)
return ActionContinue
}

View File

@ -19,10 +19,6 @@ const StateCancelled = "cancelled"
// This is the key set in the state bag when a step halted the sequence.
const StateHalted = "halted"
type StepRunnableWithContext interface {
RunWithContext(context.Context, StateBag) StepAction
}
// Step is a single step that is part of a potentially large sequence
// of other steps, responsible for performing some specific action.
type Step interface {
@ -32,7 +28,7 @@ type Step interface {
//
// The return value determines whether multi-step sequences continue
// or should halt.
Run(StateBag) StepAction
Run(context.Context, StateBag) StepAction
// Cleanup is called in reverse order of the steps that have run
// and allow steps to clean up after themselves. Do not assume if this