Documentation
¶
Index ¶
- Constants
- Variables
- func CliCheckCommand(app AppInfo, workerListProvider func(c *cli.Context) []WorkerName) cli.Command
- type AppInfo
- type Chief
- type Context
- type Event
- type EventHandler
- type EventLevel
- type Locker
- type Recover
- type Shutdown
- type StateInfo
- type Worker
- type WorkerExistRule
- type WorkerName
- type WorkerPool
- func (p *WorkerPool) FailWorker(name WorkerName) error
- func (p *WorkerPool) GetState(name WorkerName) sam.State
- func (p *WorkerPool) GetWorkersStates() map[WorkerName]sam.State
- func (p *WorkerPool) InitWorker(name WorkerName) error
- func (p *WorkerPool) IsRun(name WorkerName) bool
- func (p *WorkerPool) ReplaceWorker(name WorkerName, worker Worker)
- func (p *WorkerPool) RunWorkerExec(ctx Context, name WorkerName) (err error)
- func (p *WorkerPool) SetState(name WorkerName, state sam.State) error
- func (p *WorkerPool) SetWorker(name WorkerName, worker Worker) error
- func (p *WorkerPool) StartWorker(name WorkerName) error
- func (p *WorkerPool) StopWorker(name WorkerName) error
Constants ¶
const ( StatusAction = "status" PingAction = "ping" )
const ( WStateNotExists sam.State = "NotExists" WStateNew sam.State = "New" WStateInitialized sam.State = "Initialized" WStateRun sam.State = "Run" WStateStopped sam.State = "Stopped" WStateFailed sam.State = "Failed" )
const DefaultForceStopTimeout = 45 * time.Second
DefaultForceStopTimeout is a timeout for killing all workers.
Variables ¶
var ( ErrWorkerNotExist = func(name WorkerName) error { return fmt.Errorf("%s: not exist", name) } )
Functions ¶
func CliCheckCommand ¶ added in v2.1.0
Types ¶
type AppInfo ¶ added in v2.1.0
type AppInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Build string `json:"build"`
Tag string `json:"tag"`
}
func (AppInfo) SocketName ¶ added in v2.1.0
type Chief ¶
type Chief interface {
Run()
Shutdown()
AddWorker(WorkerName, Worker)
AddWorkers(map[WorkerName]Worker)
GetWorkersStates() map[WorkerName]sam.State
SetEventHandler(EventHandler)
SetContext(context.Context)
SetLocker(Locker)
SetRecover(Recover)
UseDefaultRecover()
SetShutdown(Shutdown)
Event() <-chan Event
EnableServiceSocket(app AppInfo, actions ...socket.Action)
}
type Context ¶
func NewContext ¶
func NewContext() Context
type Event ¶
type Event struct {
Level EventLevel
Worker WorkerName
Fields map[string]interface{}
Message string
}
func ErrorEvent ¶
func (Event) SetWorker ¶
func (e Event) SetWorker(name WorkerName) Event
type EventHandler ¶
type EventHandler func(Event)
type EventLevel ¶
type EventLevel string
const ( LvlFatal EventLevel = "fatal" LvlError EventLevel = "error" LvlInfo EventLevel = "info" )
type Recover ¶
type Recover func(name WorkerName)
type StateInfo ¶ added in v2.1.0
type StateInfo struct {
App AppInfo `json:"app"`
Workers map[WorkerName]sam.State `json:"workers"`
}
func ParseStateInfo ¶ added in v2.1.0
type Worker ¶
type Worker interface {
// Init initializes new instance of the `Worker` implementation
Init() error
// Run starts the `Worker` instance execution.
// Context should be used for listening to ctx.Done()
Run(Context) error
}
Worker is an interface for async workers which launches and manages by the `Chief`.
type WorkerExistRule ¶
type WorkerExistRule struct {
AvailableWorkers map[WorkerName]struct{}
// contains filtered or unexported fields
}
func (*WorkerExistRule) Error ¶
func (r *WorkerExistRule) Error(message string) *WorkerExistRule
Error sets the error message for the rule.
func (*WorkerExistRule) Validate ¶
func (r *WorkerExistRule) Validate(value interface{}) error
Validate checks that service exist on the system
type WorkerName ¶
type WorkerName string
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool is
func (*WorkerPool) FailWorker ¶
func (p *WorkerPool) FailWorker(name WorkerName) error
FailWorker sets state `WorkerFailed` for workers with the specified `name`.
func (*WorkerPool) GetState ¶
func (p *WorkerPool) GetState(name WorkerName) sam.State
GetState returns current state for workers with the specified `name`.
func (*WorkerPool) GetWorkersStates ¶
func (p *WorkerPool) GetWorkersStates() map[WorkerName]sam.State
GetWorkersStates returns current state of all workers.
func (*WorkerPool) InitWorker ¶
func (p *WorkerPool) InitWorker(name WorkerName) error
InitWorker initializes all present workers.
func (*WorkerPool) IsRun ¶
func (p *WorkerPool) IsRun(name WorkerName) bool
IsRun checks is active worker with passed `name`.
func (*WorkerPool) ReplaceWorker ¶
func (p *WorkerPool) ReplaceWorker(name WorkerName, worker Worker)
func (*WorkerPool) RunWorkerExec ¶
func (p *WorkerPool) RunWorkerExec(ctx Context, name WorkerName) (err error)
RunWorkerExec adds worker into pool.
func (*WorkerPool) SetState ¶
func (p *WorkerPool) SetState(name WorkerName, state sam.State) error
SetState updates state of specified worker.
func (*WorkerPool) SetWorker ¶
func (p *WorkerPool) SetWorker(name WorkerName, worker Worker) error
SetWorker adds worker into pool.
func (*WorkerPool) StartWorker ¶
func (p *WorkerPool) StartWorker(name WorkerName) error
StartWorker sets state `WorkerEnabled` for workers with the specified `name`.
func (*WorkerPool) StopWorker ¶
func (p *WorkerPool) StopWorker(name WorkerName) error
StopWorker sets state `WorkerStopped` for workers with the specified `name`.