Documentation ¶
Index ¶
- Constants
- type Error
- type Option
- type Orchestrator
- type Service
- func (s *Service) Cancel() error
- func (s *Service) CancelSucceeded() bool
- func (s *Service) Canceled() bool
- func (s *Service) Confirm() error
- func (s *Service) ConfirmSucceeded() bool
- func (s *Service) Confirmed() bool
- func (s *Service) Tried() bool
- func (s *Service) Try() error
- func (s *Service) TrySucceeded() bool
Constants ¶
const ( // ErrTryFailed means at least 1 error happened in Try phase, // but successfully canceled. ErrTryFailed = iota // ErrConfirmFailed means Try phase finished in success, but // at least 1 error happened in Confirm phase and never succeeded after some retries. // This should be never happened because if Try finished successfully, // Confirm must be finished successfully. // Basically, you need to fix inconsistent state manually ErrConfirmFailed // ErrCancelFailed means Try phase didn't finish in success, // and attempted to cancel all the services, but some resources could not be canceled. // Basically, you need to fix inconsistent state manually ErrCancelFailed )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error knows what err happened in try/confirm/cancel phase.
func (*Error) ServiceName ¶
ServiceName returns the name of service which is failed to try/confirm/cancel.
type Option ¶
type Option func(s *orchestrator)
Option can set option to service Option can be passed to NewService() and NewOrchestrator, if you pass it to both, the one which is passed to NewOrchestrator will be used
func WithMaxRetries ¶
WithMaxRetries sets limitation of retry times
type Orchestrator ¶
type Orchestrator interface {
Orchestrate() error
}
Orchestrator can orchestrate multiple service First, call every service's try() asynchronously. If all the try succeeded, call every service's confirm(). If even one of the services' try fails, every service's cancel will be called.
func NewOrchestrator ¶
func NewOrchestrator(services []*Service, opts ...Option) Orchestrator
NewOrchestrator returns interface Orchestrator
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service can be TCC service, which can Try(), Confirm(), and Cancel()
func NewService ¶
NewService returns service with passed functions
func (*Service) Cancel ¶
Cancel executes passed cancel function. This will be called after Try phase failed. In Cancel phase, service will revert the state which is changed by try phase. Basically Confirm should never return error, except network or infrastructure issues. This will be retried 10 times by default.
func (*Service) CancelSucceeded ¶
CancelSucceeded returns if the service cancel() succeeded
func (*Service) Confirm ¶
Confirm executes passed confirm function. In confirm phase, service will confirm things which is reserved in try phase. Basically Confirm should never return error, except network or infrastructure issues. This will be retried 10 times by default.
func (*Service) ConfirmSucceeded ¶
ConfirmSucceeded returns if the service confirm() succeeded
func (*Service) Try ¶
Try executes passed try function. In try phase, service will do some reservation or precondition satisfyment. After try phase is finished successfully, Confirm called. Try can fail, but if try succeeded, confirm must succeed. If try fails, Cancel will be called. Try never be retried.
func (*Service) TrySucceeded ¶
TrySucceeded returns if the service try() succeeded