process

package
v3.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 15 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CanceledByCustomerReason

type CanceledByCustomerReason struct{}

CanceledByCustomerReason is used when customer cancels order

func (CanceledByCustomerReason) Reason

func (e CanceledByCustomerReason) Reason() string

Reason for the error occurred

type CartValidationErrorReason

type CartValidationErrorReason struct {
	ValidationResult validation.Result
}

CartValidationErrorReason contains the ValidationResult

func (CartValidationErrorReason) Reason

func (e CartValidationErrorReason) Reason() string

Reason for failing

type Context

type Context struct {
	UUID               string
	CurrentStateName   string
	CurrentStateData   StateData
	PlaceOrderInfo     *application.PlaceOrderInfo
	Cart               cart.Cart
	ReturnURL          *url.URL
	RollbackReferences []RollbackReference
	FailedReason       FailedReason
}

Context contains information (state etc) about a place order process

type ContextStore

type ContextStore interface {
	Store(ctx context.Context, key string, placeOrderContext Context) error
	Get(ctx context.Context, key string) (Context, bool)
	Delete(ctx context.Context, key string) error
}

ContextStore can persist process Context instances

type ErrorOccurredReason

type ErrorOccurredReason struct {
	Error string
}

ErrorOccurredReason is used for unspecified errors

func (ErrorOccurredReason) Reason

func (e ErrorOccurredReason) Reason() string

Reason for the error occurred

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory use to get Process instance

func (*Factory) Inject

func (f *Factory) Inject(
	provider Provider,
	dep *struct {
		StartState  State `inject:"startState"`
		FailedState State `inject:"failedState"`
	},
)

Inject dependencies

func (*Factory) New

func (f *Factory) New(returnURL *url.URL, cart cart.Cart) (*Process, error)

New process with initial state

func (*Factory) NewFromProcessContext

func (f *Factory) NewFromProcessContext(pctx Context) (*Process, error)

NewFromProcessContext returns a new process with given Context

type FailedReason

type FailedReason interface {
	Reason() string
}

FailedReason gives a human readable reason for a state failure

type FatalRollbackError

type FatalRollbackError struct {
	State string
	// contains filtered or unexported fields
}

FatalRollbackError which causes the premature end of rollback process

func NewFatalRollbackError

func NewFatalRollbackError(err error, stateName string) FatalRollbackError

NewFatalRollbackError mark a rollback error as fatal, this breaks the current rollback

func (*FatalRollbackError) Error

func (f *FatalRollbackError) Error() string

type PaymentCanceledByCustomerReason

type PaymentCanceledByCustomerReason struct{}

PaymentCanceledByCustomerReason is used to signal that payment was canceled by customer

func (PaymentCanceledByCustomerReason) Reason

Reason for the error occurred

type PaymentErrorOccurredReason

type PaymentErrorOccurredReason struct {
	Error string
}

PaymentErrorOccurredReason is used for errors during payment

func (PaymentErrorOccurredReason) Reason

Reason for the error occurred

type PaymentValidatorFunc

type PaymentValidatorFunc func(ctx context.Context, p *Process, paymentService *application.PaymentService) RunResult

PaymentValidatorFunc to decide over next state depending on payment situation

type Process

type Process struct {
	// contains filtered or unexported fields
}

Process representing a place order process and has a current context with infos about result and current state

func (*Process) Context

func (p *Process) Context() Context

Context to get current process context

func (*Process) CurrentState

func (p *Process) CurrentState() (State, error)

CurrentState of the process context

func (*Process) Failed

func (p *Process) Failed(ctx context.Context, reason FailedReason)

Failed performs all collected rollbacks and switches to FailedState

func (*Process) Inject

func (p *Process) Inject(
	allStates map[string]State,
	logger flamingo.Logger,
	cfg *struct {
		Area string `inject:"config:area"`
	},
) *Process

Inject dependencies

func (*Process) Run

func (p *Process) Run(ctx context.Context)

Run triggers run on current state

func (*Process) UpdateCart

func (p *Process) UpdateCart(cartToStore cart.Cart)

UpdateCart updates the cart in the current state context

func (*Process) UpdateOrderInfo

func (p *Process) UpdateOrderInfo(info *application.PlaceOrderInfo)

UpdateOrderInfo updates the order infos of the current context

func (*Process) UpdateState

func (p *Process) UpdateState(s string, stateData StateData)

UpdateState updates the current state in the context and its related state data

type Provider

type Provider func() *Process

Provider for Processes

type RollbackData

type RollbackData interface{}

RollbackData needed for rollback of a state

type RollbackReference

type RollbackReference struct {
	StateName string
	Data      RollbackData
}

RollbackReference a reference that can be used to trigger a rollback

type RunResult

type RunResult struct {
	RollbackData RollbackData
	Failed       FailedReason
}

RunResult of a state

type State

type State interface {
	Run(context.Context, *Process) RunResult
	Rollback(context.Context, RollbackData) error
	IsFinal() bool
	Name() string
}

State interface

type StateData

type StateData interface{}

StateData holding state relevant data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL