flamingo.me/flamingo-commerce/v3@v3.11.0/checkout/domain/placeorder/states/failed.go (about) 1 package states 2 3 import ( 4 "context" 5 6 "flamingo.me/flamingo-commerce/v3/checkout/domain/placeorder/process" 7 "flamingo.me/flamingo/v3/framework/flamingo" 8 "go.opencensus.io/trace" 9 ) 10 11 type ( 12 // Failed state 13 Failed struct { 14 eventRouter flamingo.EventRouter 15 } 16 17 // FailedEvent is dispatched when the final failed state runs 18 FailedEvent struct { 19 ProcessContext process.Context 20 } 21 ) 22 23 var _ process.State = Failed{} 24 25 // Inject dependencies 26 func (f *Failed) Inject( 27 eventRouter flamingo.EventRouter, 28 ) *Failed { 29 f.eventRouter = eventRouter 30 31 return f 32 } 33 34 // Name get state name 35 func (f Failed) Name() string { 36 return "Failed" 37 } 38 39 // Run the state operations 40 func (f Failed) Run(ctx context.Context, p *process.Process) process.RunResult { 41 _, span := trace.StartSpan(ctx, "placeorder/state/Failed/Run") 42 defer span.End() 43 44 f.eventRouter.Dispatch(ctx, &FailedEvent{ 45 ProcessContext: p.Context(), 46 }) 47 48 return process.RunResult{} 49 } 50 51 // Rollback the state operations 52 func (f Failed) Rollback(_ context.Context, _ process.RollbackData) error { 53 return nil 54 } 55 56 // IsFinal if state is a final state 57 func (f Failed) IsFinal() bool { 58 return true 59 }