Documentation ¶
Index ¶
- Variables
- type Instance
- type JobArgs
- type JobContainer
- type JobFunc
- type JobsD
- func (j *JobsD) AutoMigration(run bool) *JobsD
- func (j *JobsD) CreateRun(job string, jobParams ...interface{}) *RunOnceCreator
- func (j *JobsD) Down() error
- func (j *JobsD) GetDB() *gorm.DB
- func (j *JobsD) GetInstance() Instance
- func (j *JobsD) GetLogger() logc.Logger
- func (j *JobsD) GetRunState(id int64) *RunState
- func (j *JobsD) Logger(logger logc.Logger) *JobsD
- func (j *JobsD) PollInterval(pollInt time.Duration) *JobsD
- func (j *JobsD) PollLimit(limit int) *JobsD
- func (j *JobsD) RegisterJob(name string, jobFunc interface{}) *JobContainer
- func (j *JobsD) RegisterSchedule(name string, scheduleFunc ScheduleFunc)
- func (j *JobsD) RetriesErrorLimit(limit int) *JobsD
- func (j *JobsD) RetriesTimeoutLimit(limit int) *JobsD
- func (j *JobsD) RunTimeout(timeout time.Duration) *JobsD
- func (j *JobsD) TimeoutCheck(interval time.Duration) *JobsD
- func (j *JobsD) Up() error
- func (j *JobsD) WorkerNum(workers int) *JobsD
- type Run
- type RunInfo
- type RunOnceCreator
- func (r *RunOnceCreator) RetriesErrorLimit(limit int) *RunOnceCreator
- func (r *RunOnceCreator) RetriesTimeoutLimit(limit int) *RunOnceCreator
- func (r *RunOnceCreator) Run() (int64, error)
- func (r *RunOnceCreator) RunAfter(delay time.Duration) (int64, error)
- func (r *RunOnceCreator) RunTimeout(timeout time.Duration) *RunOnceCreator
- func (r *RunOnceCreator) Schedule(schedule string) *RunScheduleCreator
- func (r *RunOnceCreator) Unique(name string) *RunOnceCreator
- type RunRes
- type RunScheduleCreator
- func (r *RunScheduleCreator) Limit(limit int) *RunScheduleCreator
- func (r *RunScheduleCreator) RetriesErrorLimit(limit int) *RunScheduleCreator
- func (r *RunScheduleCreator) RetriesTimeoutLimit(limit int) *RunScheduleCreator
- func (r *RunScheduleCreator) Run() (int64, error)
- func (r *RunScheduleCreator) RunAfter(delay time.Duration) (int64, error)
- func (r *RunScheduleCreator) RunTimeout(timeout time.Duration) *RunScheduleCreator
- func (r *RunScheduleCreator) Unique(name string) *RunScheduleCreator
- type RunState
- type Runnable
- type RunnableQueue
- type ScheduleFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( //ErrJobFuncNotFunc Job Func not a func ErrJobFuncNotFunc = errors.New("jobFunc is not a func") // ErrJobFuncNoErrRtn Job Func does not return an error ErrJobFuncNoErrRtn = errors.New("jobFunc needs to return an error") // ErrJobFuncArgsMismatch Calling Job Func args are mismatched ErrJobFuncArgsMismatch = errors.New("jobFunc calling args mismatch") )
var ErrRunKill = errors.New("job run killed")
ErrRunKill returns if a job was killed
var ErrRunTimeout = errors.New("job run timed out")
ErrRunTimeout returns if a job times out
Functions ¶
This section is empty.
Types ¶
type Instance ¶
type Instance struct { ID int64 `gorm:"primaryKey"` Workers int AutoMigrate bool SupportedJobs string SupportedSchedules string PollInterval time.Duration // When to poll the DB for Runs PollLimit int // How many Runs to get during polling TimeoutCheck time.Duration // Time between checking job runs for timeout or error RunTimeout sql.NullInt64 // Default job retry timeout RetriesOnTimeoutLimit sql.NullInt64 // Default number of retries for a job after timeout RetriesOnErrorLimit sql.NullInt64 // Default number of retries for a job after error RunsStarted int // Job runs started RunsRescheduled int // Job runs rescheduled after finishing RunsTimedOut int // Job runs timed out RunsTimedOutRes int // Job runs resurrected after time out RunsErrors int // Job runs that have returned an error LastSeenAt sql.NullTime // Last time instance was alive ShutdownAt sql.NullTime CreatedAt time.Time }
Instance .
type JobArgs ¶ added in v1.1.0
type JobArgs []interface{}
JobArgs holds job func parameters used to run a job. It can be serialized for DB storage
type JobContainer ¶
type JobContainer struct {
// contains filtered or unexported fields
}
JobContainer .
func (*JobContainer) RetriesErrorLimit ¶ added in v1.1.0
func (j *JobContainer) RetriesErrorLimit(limit int) *JobContainer
RetriesErrorLimit sets the RetriesErrorLimit Setting it to -1 removes the limit
func (*JobContainer) RetriesTimeoutLimit ¶ added in v1.1.0
func (j *JobContainer) RetriesTimeoutLimit(limit int) *JobContainer
RetriesTimeoutLimit sets how many times a job run can timeout Setting it to -1 removes the limit
func (*JobContainer) RunTimeout ¶ added in v1.1.0
func (j *JobContainer) RunTimeout(timeout time.Duration) *JobContainer
RunTimeout sets the default timeout of a job run Setting it to 0 disables timeout
type JobsD ¶
type JobsD struct {
// contains filtered or unexported fields
}
JobsD .
Example ¶
jobName := "ExampleJobsD" // Must be unique otherwise tests may collide jd := testSetup(logrus.ErrorLevel) wait := make(chan struct{}) job1Func := func(txt string) error { fmt.Printf("Hello %s!", txt) wait <- struct{}{} return nil } jd.RegisterJob(jobName, job1Func) schedule1Func := func(now time.Time) time.Time { return now.Add(500 * time.Millisecond) } jd.RegisterSchedule("schedule1", schedule1Func) err0 := jd.Up() testPanicErr(err0) _, err1 := jd.CreateRun(jobName, "World").Schedule("schedule1").Limit(1).Run() testPanicErr(err1) <-wait err2 := jd.Down() testPanicErr(err2) testTeardown(jd)
Output: Hello World!
func (*JobsD) AutoMigration ¶ added in v1.1.0
AutoMigration turns on or off auto-migration
func (*JobsD) CreateRun ¶
func (j *JobsD) CreateRun(job string, jobParams ...interface{}) *RunOnceCreator
CreateRun . Create a job run.
func (*JobsD) GetInstance ¶ added in v1.1.0
GetInstance returns the instance record
func (*JobsD) GetRunState ¶ added in v1.1.0
GetRunState retrieves the current state of the job run
func (*JobsD) PollInterval ¶ added in v1.1.0
PollInterval sets the time between getting new Runs from the DB and cluster
func (*JobsD) PollLimit ¶ added in v1.1.0
PollLimit sets the number of upcoming Runs to retrieve from the DB at a time
func (*JobsD) RegisterJob ¶
func (j *JobsD) RegisterJob(name string, jobFunc interface{}) *JobContainer
RegisterJob registers a job to be run when required. name parameter should not contain a comma. jobFunc parameter should be any func that return an error. All jobFunc params must be gob serializable.
func (*JobsD) RegisterSchedule ¶
func (j *JobsD) RegisterSchedule(name string, scheduleFunc ScheduleFunc)
RegisterSchedule adds a schedule name parameter should not contain a comma.
func (*JobsD) RetriesErrorLimit ¶ added in v1.1.0
RetriesErrorLimit sets the RetriesErrorLimit Setting it to -1 removes the limit
func (*JobsD) RetriesTimeoutLimit ¶ added in v1.1.0
RetriesTimeoutLimit sets how many times a job run can timeout Setting it to -1 removes the limit
func (*JobsD) RunTimeout ¶ added in v1.1.0
RunTimeout sets the RunTimeout Setting it to 0 disables timeout
func (*JobsD) TimeoutCheck ¶ added in v1.1.0
TimeoutCheck sets the time between retry timeout checks
type Run ¶ added in v1.1.0
type Run struct { ID int64 `gorm:"primaryKey"` OriginID int64 `gorm:"index"` Name string NameActive sql.NullString `gorm:"unique"` Job string JobArgs JobArgs Delay time.Duration RunAt time.Time RunTotalCount int RunSuccessCount int RunSuccessLimit sql.NullInt64 RunStartedAt sql.NullTime `gorm:"index"` RunStartedBy sql.NullInt64 RunCompletedAt sql.NullTime `gorm:"index"` RunCompletedError sql.NullString RunTimeout sql.NullInt64 RunTimeoutAt sql.NullTime `gorm:"index"` RetriesOnErrorCount int RetriesOnErrorLimit sql.NullInt64 RetriesOnTimeoutCount int RetriesOnTimeoutLimit sql.NullInt64 Schedule sql.NullString CreatedAt time.Time `gorm:"index"` CreatedBy int64 }
Run is a database representation of a job run
type RunInfo ¶ added in v1.1.0
type RunInfo struct { ID int64 OriginID int64 Name string Job string JobArgs JobArgs RunAt time.Time RunTotalCount int RunSuccessCount int RunSuccessLimit *int RunStartedAt time.Time RunStartedBy int64 RunTimeout time.Duration RunTimeoutAt *time.Time RetriesOnErrorCount int RetriesOnErrorLimit *int RetriesOnTimeoutCount int RetriesOnTimeoutLimit *int Schedule *string CreatedAt time.Time CreatedBy int64 Cancel <-chan struct{} }
RunInfo exposes information and functions to a running job
type RunOnceCreator ¶
type RunOnceCreator struct {
// contains filtered or unexported fields
}
RunOnceCreator creates a job run that runs only once
func (*RunOnceCreator) RetriesErrorLimit ¶ added in v1.1.0
func (r *RunOnceCreator) RetriesErrorLimit(limit int) *RunOnceCreator
RetriesErrorLimit sets the RetriesErrorLimit Setting it to -1 removes the limit
func (*RunOnceCreator) RetriesTimeoutLimit ¶ added in v1.1.0
func (r *RunOnceCreator) RetriesTimeoutLimit(limit int) *RunOnceCreator
RetriesTimeoutLimit sets how many times a job run can timeout Setting it to -1 removes the limit
func (*RunOnceCreator) Run ¶
func (r *RunOnceCreator) Run() (int64, error)
Run the job returns the Job Run ID and Error
func (*RunOnceCreator) RunAfter ¶
func (r *RunOnceCreator) RunAfter(delay time.Duration) (int64, error)
RunAfter the job returns the Job Run ID and Error
func (*RunOnceCreator) RunTimeout ¶ added in v1.1.0
func (r *RunOnceCreator) RunTimeout(timeout time.Duration) *RunOnceCreator
RunTimeout sets the RunTimeout Setting it to 0 disables timeout
func (*RunOnceCreator) Schedule ¶
func (r *RunOnceCreator) Schedule(schedule string) *RunScheduleCreator
Schedule the job
func (*RunOnceCreator) Unique ¶
func (r *RunOnceCreator) Unique(name string) *RunOnceCreator
Unique gives the run a unique name across the cluster. i.e only one job with a unique name can be running or jobsd at the same time.
type RunScheduleCreator ¶
type RunScheduleCreator struct {
// contains filtered or unexported fields
}
RunScheduleCreator create a job run that runs according to a schedule
func (*RunScheduleCreator) Limit ¶
func (r *RunScheduleCreator) Limit(limit int) *RunScheduleCreator
Limit sets how many times the job can successfully run
func (*RunScheduleCreator) RetriesErrorLimit ¶ added in v1.1.0
func (r *RunScheduleCreator) RetriesErrorLimit(limit int) *RunScheduleCreator
RetriesErrorLimit sets the RetriesErrorLimit Setting it to -1 removes the limit
func (*RunScheduleCreator) RetriesTimeoutLimit ¶ added in v1.1.0
func (r *RunScheduleCreator) RetriesTimeoutLimit(limit int) *RunScheduleCreator
RetriesTimeoutLimit sets how many times a job run can timeout Setting it to -1 removes the limit
func (*RunScheduleCreator) Run ¶
func (r *RunScheduleCreator) Run() (int64, error)
Run the job according to the schedule returns the Job Run ID and Error
func (*RunScheduleCreator) RunAfter ¶
func (r *RunScheduleCreator) RunAfter(delay time.Duration) (int64, error)
RunAfter the specified duration returns the Job Run ID and Error
func (*RunScheduleCreator) RunTimeout ¶ added in v1.1.0
func (r *RunScheduleCreator) RunTimeout(timeout time.Duration) *RunScheduleCreator
RunTimeout sets the RunTimeout Setting it to 0 disables timeout
func (*RunScheduleCreator) Unique ¶
func (r *RunScheduleCreator) Unique(name string) *RunScheduleCreator
Unique gives the run a unique name across the cluster. i.e only one job with a unique name can be running or jobsd at the same time.
type RunState ¶ added in v1.1.0
type RunState struct { OriginID int64 Name string Job string Schedule *string RunSuccessCount int RunStartedAt *time.Time RunStartedBy *int64 RunCompletedAt *time.Time RunCompletedError *string RetriesOnErrorCount int RetriesOnTimeoutCount int CreatedAt time.Time CreatedBy int64 // contains filtered or unexported fields }
RunState is a snapshot of a job runs latest state
type Runnable ¶ added in v1.1.0
type Runnable struct {
// contains filtered or unexported fields
}
Runnable represents a single runnable job run
type RunnableQueue ¶ added in v1.1.0
type RunnableQueue struct {
// contains filtered or unexported fields
}
RunnableQueue is a priority queue of jobs to run