job

package
v0.0.0-...-20810c9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 2 Imported by: 0

README

Job

"github.com/axe/axe-go/pkg/job"

Jobs are responsible for organizing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	// The unique ID of this job
	ID int
	// The name of this job
	Name string
	// The group of this job which dictates ordering
	Group uint8
	// The cost of this job
	Cost int
	// If this job should be executed asynchronously
	Async bool
	// If this job should only be executed after a job with this ID is
	After int
	// If the job should stricly follow the wait times. So if the wait time is 20 then the job will try to run 50 times a second exactly.
	Strict bool
	// The minimum milliseconds we should wait between execution
	MinWait int64
	// The maximum milliseconds we should wait between execution
	MaxWait int64
	// The last computed wait time
	WaitTime int64
	// The last time this job ran
	LastRun int64
	// The last duration between the last run and the previous run
	LastDuration int64
	// If the job should be profiled
	Profile bool
	// The last profile start in nanos
	ProfileStart int64
	// The last profile end in nanos
	ProfileEnd int64
	// The logic which executes the job
	Logic JobLogic
}

func New

func New(defaults Job) *Job

func (*Job) GetWaitTime

func (job *Job) GetWaitTime(time int64, planned map[int]bool) int64

func (*Job) IsBehind

func (job *Job) IsBehind(time int64) bool

func (*Job) Less

func (job *Job) Less(other *Job) bool

func (*Job) Run

func (job *Job) Run(time int64, profile bool)

func (*Job) SetFrequency

func (job *Job) SetFrequency(frequency int64)

func (*Job) UpdateWaitTime

func (job *Job) UpdateWaitTime(time int64, planned map[int]bool)

type JobDependency

type JobDependency struct {
	Dependency *Job
	Dependent  *Job
	Required   bool
}

type JobGroup

type JobGroup struct {
	Jobs  ds.List[*Job]
	Ready ds.SortableList[*Job]
}

func (*JobGroup) Add

func (g *JobGroup) Add(job *Job)

type JobLogic

type JobLogic interface {
	Run(job *Job)
	IsActive() bool
	IsAlive() bool
}

type JobRunner

type JobRunner struct {
	Groups     []JobGroup
	Ready      ds.SortableList[*Job]
	Planned    map[int]bool
	Dependency map[int]bool
	// How much we can afford to run
	Budget    int
	TotalCost int
	Profile   bool

	LastDuration int64
	LastRun      int64
	ProfileStart int64
	ProfileEnd   int64
}

func NewRunner

func NewRunner(groups int, budget int) *JobRunner

func (*JobRunner) Add

func (r *JobRunner) Add(job *Job)

func (*JobRunner) Create

func (r *JobRunner) Create(job Job) *Job

func (*JobRunner) Run

func (r *JobRunner) Run()

func (*JobRunner) SortReady

func (r *JobRunner) SortReady()

func (*JobRunner) Unready

func (r *JobRunner) Unready(job *Job)

func (*JobRunner) UnreadyDependency

func (r *JobRunner) UnreadyDependency(id int)

func (*JobRunner) UnreadyLast

func (r *JobRunner) UnreadyLast()

Jump to

Keyboard shortcuts

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