Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidToken is returned when caller of the ProcessMessage function // does not pass a valid token written by Runner in its Token channel. ErrInvalidToken = errors.New("invalid token") // ErrCheckWithSameID is returned when the runner is about to run a check // with and ID equal to the ID of an already running check. ErrCheckWithSameID = errors.New("check with a same ID is already running") // DefaultMaxMessageProcessedTimes defines the maximun number of times the // processor tries to processe a checks message before it declares the check // as failed. DefaultMaxMessageProcessedTimes = 200 )
Functions ¶
This section is empty.
Types ¶
type AbortedChecks ¶
AbortedChecks defines the shape of the component needed by a Runner in order to know if a check is aborted before it is exected.
type CheckStateUpdater ¶
type CheckStateUpdater interface { UpdateState(stateupdater.CheckState) error UploadCheckData(checkID, kind string, startedAt time.Time, content []byte) (string, error) CheckStatusTerminal(ID string) bool FlushCheckStatus(ID string) error UpdateCheckStatusTerminal(stateupdater.CheckState) }
type Job ¶
type Job struct { CheckID string `json:"check_id"` // Required StartTime time.Time `json:"start_time"` // Required Image string `json:"image"` // Required Target string `json:"target"` // Required Timeout int `json:"timeout"` // Required AssetType string `json:"assettype"` // Optional Options string `json:"options"` // Optional RequiredVars []string `json:"required_vars"` // Optional Metadata map[string]string `json:"metadata"` // Optional RunTime int64 }
Job stores the information necessary to create a new check job. This is the information written in the queue where the agents read the messages from.
type Runner ¶
type Runner struct { Backend backend.Backend // Tokens contains the currently free tokens of a runner. Any // caller of the Run function must take a token from this channel before // actually calling "Run" in order to ensure there are no more than // maxTokens jobs running at the same time. Tokens chan interface{} Logger log.Logger CheckUpdater CheckStateUpdater // contains filtered or unexported fields }
Runner runs the checks associated to a concreate message by receiving calls to it ProcessMessage function.
func New ¶
func New(logger log.Logger, backend backend.Backend, checkUpdater CheckStateUpdater, aborted AbortedChecks, cfg RunnerConfig) *Runner
New creates a Runner initialized with the given log, backend and maximun number of tokens. The maximum number of tokens is the maximun number jobs that the Runner can execute at the same time.
func (*Runner) AbortAllChecks ¶
AbortAllChecks aborts all the checks that are running.
func (*Runner) AbortCheck ¶
AbortCheck aborts a check if it is running.
func (*Runner) ChecksRunning ¶
ChecksRunning returns the current number of checks running.
func (*Runner) FreeTokens ¶
func (cr *Runner) FreeTokens() chan interface{}
FreeTokens returns a channel that can be used to get a free token to call the ProcessMessage method.
func (*Runner) ProcessMessage ¶
ProcessMessage executes the job specified in a message given a free token that must be obtained from the Tokens channel. The func does not actually do anything with the token, the parameter is present just to make obvious that there must be free tokens on the channel before calling this method. When the message if processed the channel returned will indicate if the message must be deleted or not.
type RunnerConfig ¶
RunnerConfig contains config parameters for a Runner.