Documentation
¶
Index ¶
- Constants
- Variables
- type Cache
- type ChangeEvent
- type Ctx
- type DoFunc
- type Group
- type Job
- type JobFunc
- type JobReference
- type MemoryStorage
- type Option
- type Reactr
- func (h *Reactr) Do(job Job) *Result
- func (h *Reactr) Handle(jobType string, runner Runnable, options ...Option) JobFunc
- func (h *Reactr) HandleMsg(pod *grav.Pod, msgType string, runner Runnable, options ...Option)
- func (h *Reactr) Job(jobType string, data interface{}) Job
- func (h *Reactr) Listen(pod *grav.Pod, msgType string)
- func (h *Reactr) Schedule(s Schedule)
- type Result
- type ResultFunc
- type RunErr
- type Runnable
- type Schedule
- type Storage
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 Reactr job
Variables ¶
var ErrCacheKeyNotFound = errors.New("key not found")
ErrCacheKeyNotFound is returned when a non-existent cache key is requested
var (
ErrJobNotFound = errors.New("job not found in storage")
)
ErrJobNotFound and others are storage realated errors
var (
ErrJobTimeout = errors.New("job timeout")
)
ErrJobTimeout and others are errors related to workers
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
Set(key string, val []byte, ttl int) error
Get(key string) ([]byte, error)
Delete(key string) error
}
Cache represents access to a persistent cache
type ChangeEvent ¶
type ChangeEvent int
ChangeEvent represents a change relevant to a worker
const (
ChangeTypeStart ChangeEvent = iota
)
ChangeTypeStart and others represent types of changes
type Ctx ¶
type Ctx struct {
Cache Cache
// contains filtered or unexported fields
}
Ctx is a Job context
type Job ¶
type Job struct {
JobReference
// contains filtered or unexported fields
}
Job describes a job to be done
func (Job) Reference ¶
func (j Job) Reference() JobReference
Reference returns a reference to the Job
type JobFunc ¶
type JobFunc func(interface{}) *Result
JobFunc is a function that runs a job of a predetermined type
type JobReference ¶
type JobReference struct {
// contains filtered or unexported fields
}
JobReference is a lightweight reference to a Job
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage is the default in-memory storage driver for Reactr
func (*MemoryStorage) AddResult ¶
func (m *MemoryStorage) AddResult(uuid string, data interface{}, err error) error
AddResult adds a Job result to storage
func (*MemoryStorage) Get ¶
func (m *MemoryStorage) Get(uuid string) (Job, error)
Get loads a Job and any of its results from storage
func (*MemoryStorage) Remove ¶
func (m *MemoryStorage) Remove(uuid string) error
Remove removes a Job and its data from storage
type Option ¶
type Option func(workerOpts) workerOpts
Option is a function that modifies workerOpts
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 Reactr ¶
type Reactr struct {
// contains filtered or unexported fields
}
Reactr represents the main control object
func (*Reactr) Handle ¶
Handle registers a Runnable with the Reactr and returns a shortcut function to run those jobs
func (*Reactr) HandleMsg ¶
HandleMsg registers a Runnable with the Reactr and triggers that job whenever the provided Grav pod receives a message of a particular type.
func (*Reactr) Listen ¶
Listen causes Reactr 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.
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 ¶ added in v0.8.0
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 Schedule ¶ added in v0.7.0
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.