goyaad

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NextID

func NextID() uint64

NextID generates the next int id monotonically increasing

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub is a time ordered collection of spokes

func NewHub

func NewHub(opts *HubOpts) *Hub

NewHub creates a new hub where adjacent spokes lie at the given spokeSpan duration boundary.

func (*Hub) AddJobLocked added in v1.2.0

func (h *Hub) AddJobLocked(j *Job) error

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

func (h *Hub) CancelJobLocked(jobID string) error

CancelJobLocked cancels a job if found. Calls are noop for unknown jobs

func (*Hub) GetNJobs added in v1.0.0

func (h *Hub) GetNJobs(n int) chan *Job

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

func (h *Hub) NextLocked() *Job

NextLocked returns the next job that is ready now or returns nil.

func (*Hub) PersistLocked added in v1.2.0

func (h *Hub) PersistLocked() chan error

PersistLocked locks the hub and starts persisting data to disk

func (*Hub) Prune

func (h *Hub) Prune() int

Prune clears spokes which are expired and have no jobs returns the number of spokes pruned

func (*Hub) Restore added in v1.0.0

func (h *Hub) Restore() error

Restore loads any jobs saved to disk at the given path

func (*Hub) Stats added in v1.2.0

func (h *Hub) Stats() stats.Snapshot

Stats returns a snapshot of the current hubs stats

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

func (*Hub) Stop added in v1.0.0

func (h *Hub) Stop(persist bool)

Stop the hub gracefully and if persist is true, then persist all jobs to disk for later recovery

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.

func (*Item) Priority

func (i *Item) Priority() time.Time

Priority of the item

func (*Item) Value

func (i *Item) Value() interface{}

Value pointed to by the item

type Job

type Job struct {
	// contains filtered or unexported fields
}

Job is the basic unit of work in yaad

func NewJob

func NewJob(id string, triggerAt time.Time, b []byte) *Job

NewJob creates a new yaad job

func NewJobAutoID

func NewJobAutoID(triggerAt time.Time, b []byte) *Job

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

func (j *Job) AsPriorityItem() *Item

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

func (*Job) Body

func (j *Job) Body() []byte

Body returns the job of the job

func (*Job) GobDecode added in v1.0.0

func (j *Job) GobDecode(data []byte) error

GobDecode encodes a job into a binary buffer

func (*Job) GobEncode added in v1.0.0

func (j *Job) GobEncode() (data []byte, err error)

GobEncode encodes a job into a binary buffer

func (*Job) ID

func (j *Job) ID() string

ID returns the id of the job

func (*Job) IsReady

func (j *Job) IsReady() bool

IsReady returns true if job is ready to be worked on

func (*Job) SetOpts

func (j *Job) SetOpts(pri int32, ttr time.Duration)

SetOpts sets job options

func (*Job) TriggerAt

func (j *Job) TriggerAt() time.Time

TriggerAt returns the job's trigger 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 NewSpoke

func NewSpoke(start, end time.Time) *Spoke

NewSpoke creates a new spoke to hold jobs

func NewSpokeFromNow

func NewSpokeFromNow(duration time.Duration) *Spoke

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

func (s *Spoke) AddJobLocked(j *Job) error

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

func (s *Spoke) AsPriorityItem() *Item

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

func (s *Spoke) CancelJobLocked(id string) error

CancelJobLocked will try to delete a job that hasn't been consumed yet

func (*Spoke) GetLocker

func (s *Spoke) GetLocker() sync.Locker

GetLocker returns the spoke as a sync.Locker interface

func (*Spoke) ID

func (s *Spoke) ID() uuid.UUID

ID returns the id of this spoke

func (*Spoke) Lock

func (s *Spoke) Lock()

Lock this spoke

func (*Spoke) NextLocked added in v1.2.0

func (s *Spoke) NextLocked() *Job

NextLocked returns the next ready job

func (*Spoke) OwnsJobLocked added in v1.2.0

func (s *Spoke) OwnsJobLocked(id string) bool

OwnsJobLocked returns true if a job by given id is owned by this spoke

func (*Spoke) PendingJobsLen

func (s *Spoke) PendingJobsLen() int

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

func (*Spoke) Unlock

func (s *Spoke) Unlock()

Unlock 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
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL