Documentation ¶
Index ¶
- Constants
- Variables
- type ChangeEvent
- type Ctx
- type DoFunc
- type FFIResult
- type FFIVariable
- type Group
- type Job
- type JobFunc
- type Option
- type Result
- type ResultFunc
- type RunErr
- type Runnable
- type ScalerMetrics
- type Schedule
- type Scheduler
- func (r *Scheduler) DeRegister(jobType string) error
- func (r *Scheduler) Do(job Job) *Result
- func (r *Scheduler) IsRegistered(jobType string) bool
- func (r *Scheduler) Job(jobType string, data interface{}) Job
- func (r *Scheduler) Listen(pod *bus.Pod, msgType string)
- func (r *Scheduler) ListenAndRun(pod *bus.Pod, msgType string, run func(bus.Message, interface{}, error))
- func (r *Scheduler) Metrics() ScalerMetrics
- func (r *Scheduler) Register(jobType string, runner Runnable, options ...Option) JobFunc
- func (r *Scheduler) Schedule(s Schedule)
- type WorkerMetrics
Constants ¶
const ( MsgTypeReactrJobErr = "reactr.joberr" // any kind of error from a job run MsgTypeReactrRunErr = "reactr.runerr" // specifically a RunErr returned from a Wasm Runnable MsgTypeReactrResult = "reactr.result" MsgTypeReactrNilResult = "reactr.nil" )
MsgTypeReactrJobErr and others are Grav message types used for Scheduler job
Variables ¶
var (
ErrJobTimeout = errors.New("job timeout")
)
ErrJobTimeout and others are errors related to workers
Functions ¶
This section is empty.
Types ¶
type ChangeEvent ¶
type ChangeEvent int
ChangeEvent represents a change relevant to a worker
const ( ChangeTypeStart ChangeEvent = iota ChangeTypeStop ChangeEvent = iota )
ChangeTypeStart and others represent types of changes
type Ctx ¶
Ctx is a Job context
func (*Ctx) HasFFIResult ¶
HasFFIResult returns true if the Ctx has a current FFI result
func (*Ctx) UseFFIResult ¶
func (*Ctx) UseVars ¶
func (c *Ctx) UseVars() ([]FFIVariable, error)
UseVars returns the list of variables that the Wasm module has set on this Ctx. They are ordered and named. Since the variables can only be used by one host call, they are cleared after being returned.
type FFIVariable ¶
type FFIVariable struct { Name string Value interface{} }
FFIVariable is a variable that a Wasm Runnable can store host-side to be used in a host call such as a DB query. They are both ordered AND named, stored on the instance itself.
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job describes a job to be done
func (Job) Req ¶
func (j Job) Req() *request.CoordinatedRequest
Req returns the Coordinated request attached to the Job
type JobFunc ¶
type JobFunc func(interface{}) *Result
JobFunc is a function that runs a job of a predetermined type
type Option ¶
type Option func(workerOpts) workerOpts
Option is a function that modifies workerOpts
func Autoscale ¶
Autoscale returns an Option that enables autoscaling and sets the max number of threads
func MaxRetries ¶
MaxRetries returns an Option to set the worker maximum retry count
func PreWarm ¶
func PreWarm() Option
PreWarm sets the worker to pre-warm itself to minimize cold start time. if not enabled, worker will "warm up" when it receives its first job.
func RetrySeconds ¶
RetrySeconds returns an Option to set the worker retry seconds
func TimeoutSeconds ¶
TimeoutSeconds returns an Option with the job timeout seconds set
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result describes a result
func (*Result) Discard ¶
func (r *Result) Discard()
Discard returns immediately and discards the eventual results and thus prevents the memory from hanging around
func (*Result) ThenDo ¶
func (r *Result) ThenDo(do ResultFunc)
ThenDo accepts a callback function to be called asynchronously when the result completes.
type ResultFunc ¶
type ResultFunc func(interface{}, error)
ResultFunc is a result callback function.
type RunErr ¶
RunErr represents an error returned from a Wasm Runnable it lives in the rt package to avoid import cycles
type Runnable ¶
type Runnable interface { // Run is the entrypoint for jobs handled by a Runnable Run(Job, *Ctx) (interface{}, error) // OnChange is called when the worker using the Runnable instance is going to change. // OnChange will be called for things like startup and shutdown. OnChange(ChangeEvent) error }
Runnable describes something that is runnable
type ScalerMetrics ¶
type ScalerMetrics struct { TotalThreadCount int `json:"totalThreadCount"` TotalJobCount int `json:"totalJobCount"` Workers map[string]WorkerMetrics `json:"workers"` }
ScalerMetrics is internal metrics about the scaler
type Schedule ¶
Schedule is a type that returns an *optional* job if there is something that should be scheduled. Reactr will poll the Check() method at regular intervals to see if work is available.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler represents the main control object
func NewWithLogger ¶
NewWithLogger returns a Scheduler with a custom logger
func (*Scheduler) DeRegister ¶
DeRegister stops the workers for a given jobType and removes it
func (*Scheduler) IsRegistered ¶
IsRegistered returns true if the instance has a worker registered for the given jobType
func (*Scheduler) Listen ¶
Listen causes Scheduler to listen for messages of the given type and trigger the job of the same type. The message's data is passed to the runnable as the job data. The job's result is then emitted as a message. If an error occurs, it is logged and an error is sent. If the result is nil, nothing is sent.
func (*Scheduler) ListenAndRun ¶
func (r *Scheduler) ListenAndRun(pod *bus.Pod, msgType string, run func(bus.Message, interface{}, error))
ListenAndRun subscribes Scheduler to a messageType and calls `run` for each job result
func (*Scheduler) Metrics ¶
func (r *Scheduler) Metrics() ScalerMetrics
Metrics returns a snapshot in time describing Scheduler's internals