Documentation ¶
Index ¶
- Variables
- func NextID() uint64
- type Hub
- func (h *Hub) AddJobLocked(j *Job) error
- func (h *Hub) CancelJobLocked(jobID string) error
- func (h *Hub) GetNJobs(n int) chan *Job
- func (h *Hub) NextLocked() *Job
- func (h *Hub) PersistLocked() chan error
- func (h *Hub) Prune() int
- func (h *Hub) Restore() error
- func (h *Hub) Stats() stats.Snapshot
- func (h *Hub) StatusLocked()
- func (h *Hub) StatusPrinter()
- func (h *Hub) Stop(persist bool)
- type HubOpts
- type Item
- type Job
- func (j *Job) AsBound(spokeSpan time.Duration) SpokeBound
- func (j *Job) AsPriorityItem() *Item
- func (j *Job) AsTemporalState() TemporalState
- func (j *Job) Body() []byte
- func (j *Job) GobDecode(data []byte) error
- func (j *Job) GobEncode() (data []byte, err error)
- func (j *Job) ID() string
- func (j *Job) IsReady() bool
- func (j *Job) SetOpts(pri int32, ttr time.Duration)
- func (j *Job) TriggerAt() time.Time
- type PriorityQueue
- type Spoke
- func (s *Spoke) AddJobLocked(j *Job) error
- func (s *Spoke) AsPriorityItem() *Item
- func (s *Spoke) AsTemporalState() TemporalState
- func (s *Spoke) CancelJobLocked(id string) error
- func (s *Spoke) GetLocker() sync.Locker
- func (s *Spoke) ID() uuid.UUID
- func (s *Spoke) Lock()
- func (s *Spoke) NextLocked() *Job
- func (s *Spoke) OwnsJobLocked(id string) bool
- func (s *Spoke) PendingJobsLen() int
- func (s *Spoke) PersistLocked(p persistence.Persister) chan error
- func (s *Spoke) Unlock()
- type SpokeBound
- type TemporalState
Constants ¶
This section is empty.
Variables ¶
var ErrJobOutOfSpokeBounds = errors.New("The offered job is outside the bounds of this spoke ")
ErrJobOutOfSpokeBounds is returned when an attempt was made to add a job to a spoke that should not contain it - the job's trigger time it outside the spoke bounds
Functions ¶
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is a time ordered collection of spokes
func NewHub ¶
NewHub creates a new hub where adjacent spokes lie at the given spokeSpan duration boundary.
func (*Hub) AddJobLocked ¶ added in v1.2.0
AddJobLocked to this hub. Hub should never reject a job - this method will panic if that happens
func (*Hub) CancelJobLocked ¶ added in v1.2.0
CancelJobLocked cancels a job if found. Calls are noop for unknown jobs
func (*Hub) GetNJobs ¶ added in v1.0.0
GetNJobs returns upto N jobs (or less if there are less jobs in available) It does not return a consistent snapshot of jobs but provides a best effort view
func (*Hub) NextLocked ¶ added in v1.2.0
NextLocked returns the next job that is ready now or returns nil.
func (*Hub) PersistLocked ¶ added in v1.2.0
PersistLocked locks the hub and starts persisting data to disk
func (*Hub) Prune ¶
Prune clears spokes which are expired and have no jobs returns the number of spokes pruned
func (*Hub) StatusLocked ¶ added in v1.2.0
func (h *Hub) StatusLocked()
StatusLocked prints the state of the spokes of this hub
func (*Hub) StatusPrinter ¶
func (h *Hub) StatusPrinter()
StatusPrinter starts a status printer that prints hub stats over some time interval
type HubOpts ¶ added in v1.0.0
type HubOpts struct { Persister persistence.Persister // persister to store/restore from disk AttemptRestore bool // If true, hub will try to restore from disk on start SpokeSpan time.Duration // How wide should the spokes be }
HubOpts define customizations for Hub initialization
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
An Item is something we manage in a priority queue.
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job is the basic unit of work in yaad
func NewJobAutoID ¶
NewJobAutoID creates a job a job id assigned automatically
func (*Job) AsBound ¶
func (j *Job) AsBound(spokeSpan time.Duration) SpokeBound
AsBound returns spokeBound for a hypothetical spoke that should hold this job
func (*Job) AsPriorityItem ¶
AsPriorityItem returns this job as a prioritizable item
func (*Job) AsTemporalState ¶
func (j *Job) AsTemporalState() TemporalState
AsTemporalState returns the job's temporal classification at the point in time
type PriorityQueue ¶
type PriorityQueue []*Item
A PriorityQueue implements heap.Interface and holds Items.
func (PriorityQueue) AtIdx ¶
func (pq PriorityQueue) AtIdx(i int) *Item
AtIdx gets item at given index
func (PriorityQueue) Cap ¶
func (pq PriorityQueue) Cap() int
Cap returns the current capacity of the underlying array of the Priority Queue
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
Len returns the current length of the underlying array of the PriorityQueue
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
Less defines item ordering. Priority is defined by trigger time in the future
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
Pop the item with the closest trigger time (priority)
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x interface{})
Push an item to this PriorityQueue
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type Spoke ¶
type Spoke struct { SpokeBound // contains filtered or unexported fields }
Spoke is a time bound chain of jobs
func NewSpokeFromNow ¶
NewSpokeFromNow creates a new spoke to hold jobs that starts from now and ends at the given duration
func (*Spoke) AddJobLocked ¶ added in v1.2.0
AddJobLocked submits a job to the spoke. If the spoke cannot take responsibility of this job, it will return it as it is, otherwise nil is returned
func (*Spoke) AsPriorityItem ¶
AsPriorityItem returns a spoke as a prioritizable Item
func (*Spoke) AsTemporalState ¶
func (s *Spoke) AsTemporalState() TemporalState
AsTemporalState returns the spoke's temporal classification at the point in time
func (*Spoke) CancelJobLocked ¶ added in v1.2.0
CancelJobLocked will try to delete a job that hasn't been consumed yet
func (*Spoke) NextLocked ¶ added in v1.2.0
NextLocked returns the next ready job
func (*Spoke) OwnsJobLocked ¶ added in v1.2.0
OwnsJobLocked returns true if a job by given id is owned by this spoke
func (*Spoke) PendingJobsLen ¶
PendingJobsLen returns the number of jobs remaining in this spoke
func (*Spoke) PersistLocked ¶ added in v1.2.0
func (s *Spoke) PersistLocked(p persistence.Persister) chan error
PersistLocked all jobs in this spoke
type SpokeBound ¶ added in v1.0.0
type SpokeBound struct {
// contains filtered or unexported fields
}
SpokeBound defines time bounds for a spoke
func (*SpokeBound) Contains ¶ added in v1.0.0
func (sb *SpokeBound) Contains(o *SpokeBound) bool
Contains returns true if sb fully contains o
func (*SpokeBound) ContainsJob ¶ added in v1.0.0
func (sb *SpokeBound) ContainsJob(j *Job) bool
ContainsJob returns true if this job is bounded by this spoke
func (*SpokeBound) End ¶ added in v1.0.0
func (sb *SpokeBound) End() time.Time
End returns the ending time of this spoke bound (exclusive)
func (*SpokeBound) IsExpired ¶ added in v1.0.0
func (sb *SpokeBound) IsExpired() bool
IsExpired returns true if SpokeBound ended in the past
func (*SpokeBound) IsReady ¶ added in v1.0.0
func (sb *SpokeBound) IsReady() bool
IsReady returns true if SpokeBound started in the past This spoke bound may end in the future
func (*SpokeBound) Start ¶ added in v1.0.0
func (sb *SpokeBound) Start() time.Time
Start returns the starting time of this spoke bound (inclusive)
type TemporalState ¶
type TemporalState int
TemporalState is a classification of time for an object
const ( // Past in time Past TemporalState = iota // Current in time Current // Future in time Future )