Documentation
¶
Index ¶
- Constants
- Variables
- func Decode(p string, v any) error
- func Encode(v any) (string, error)
- func MustDecode(p string, v any)
- func MustEncode(v any) string
- type Job
- type JobChain
- type JobChainer
- type JobLog
- type JobLogWriter
- type JobManager
- type JobRunner
- func (jr *JobRunner) Abort(reason string) error
- func (jr *JobRunner) AddResult(result string) error
- func (jr *JobRunner) Cancel(reason string) error
- func (jr *JobRunner) ChainID() int64
- func (jr *JobRunner) Checkout() error
- func (jr *JobRunner) Finish() error
- func (jr *JobRunner) GetJob(cols ...string) (*Job, error)
- func (jr *JobRunner) JobID() int64
- func (jr *JobRunner) JobLogWriter() *JobLogWriter
- func (jr *JobRunner) JobManager() JobManager
- func (jr *JobRunner) JobName() string
- func (jr *JobRunner) JobParam() string
- func (jr *JobRunner) Locale() string
- func (jr *JobRunner) Log() *log.Log
- func (jr *JobRunner) Pin() error
- func (jr *JobRunner) RunnerID() int64
- func (jr *JobRunner) Running(ctx context.Context, getTimeout, pinTimeout time.Duration) error
- func (jr *JobRunner) SetState(state string) error
Constants ¶
View Source
const ( JobStatusAborted = "A" JobStatusCanceled = "C" JobStatusFinished = "F" JobStatusPending = "P" JobStatusRunning = "R" )
Variables ¶
View Source
var ( JobDoneStatus = []string{JobStatusAborted, JobStatusCanceled, JobStatusFinished} JobUndoneStatus = []string{JobStatusPending, JobStatusRunning} )
View Source
var ( ErrJobAborted = errors.New("job aborted") // indicates this job status is aborted ErrJobCanceled = errors.New("job canceled") // indicates this job status is canceled ErrJobComplete = errors.New("job complete") // indicates this job is complete, should update job status to Finished ErrJobCheckout = errors.New("job checkout failed") ErrJobPin = errors.New("job pin failed") ErrJobMissing = errors.New("job missing") ErrJobExisting = errors.New("job existing") // indicates job already existing (for multiple runnable job) )
View Source
var ( JobLogLevelFatal = log.LevelFatal.Prefix() JobLogLevelError = log.LevelError.Prefix() JobLogLevelWarn = log.LevelWarn.Prefix() JobLogLevelInfo = log.LevelInfo.Prefix() JobLogLevelDebug = log.LevelDebug.Prefix() JobLogLevelTrace = log.LevelTrace.Prefix() )
View Source
var (
ErrJobChainMissing = errors.New("jobchain missing")
)
Functions ¶
func MustDecode ¶ added in v1.0.17
func MustEncode ¶ added in v1.0.17
Types ¶
type Job ¶
type Job struct {
ID int64 `gorm:"not null;primaryKey;autoIncrement" json:"id,omitempty"`
CID int64 `gorm:"column:cid;not null" json:"cid,omitempty"`
RID int64 `gorm:"column:rid;not null" json:"rid,omitempty"`
Name string `gorm:"size:250;not null;index:idx_jobs_name" json:"name,omitempty"`
Status string `gorm:"size:1;not null" json:"status,omitempty"`
Locale string `gorm:"size:20;not null" json:"locale,omitempty"`
Param string `gorm:"not null" json:"param,omitempty"`
State string `gorm:"not null" form:"state" json:"state,omitempty"`
Result string `gorm:"not null" json:"result,omitempty"`
Error string `gorm:"not null" json:"error,omitempty"`
CreatedAt time.Time `gorm:"not null;<-:create" json:"created_at,omitempty"`
UpdatedAt time.Time `gorm:"not null" json:"updated_at,omitempty"`
}
func (*Job) IsCanceled ¶ added in v1.0.27
func (*Job) IsFinished ¶ added in v1.0.27
type JobChain ¶ added in v1.0.17
type JobChain struct {
ID int64 `gorm:"not null;primaryKey;autoIncrement" json:"id,omitempty"`
Name string `gorm:"size:250;not null;index:idx_job_chains_name" json:"name,omitempty"`
Status string `gorm:"size:1;not null" json:"status,omitempty"`
States string `gorm:"not null" json:"states,omitempty"`
CreatedAt time.Time `gorm:"not null;<-:create" json:"created_at,omitempty"`
UpdatedAt time.Time `gorm:"not null" json:"updated_at,omitempty"`
}
func (*JobChain) IsCanceled ¶ added in v1.0.27
func (*JobChain) IsFinished ¶ added in v1.0.27
type JobChainer ¶ added in v1.0.17
type JobChainer interface {
// GetJobChain get a job chain
GetJobChain(cid int64) (*JobChain, error)
// FindJobChain find a job chain
// name: name to filter (optional)
// status: status to filter (optional)
FindJobChain(name string, asc bool, status ...string) (*JobChain, error)
// FindJobChains find job chains
// name: name to filter (optional)
// status: status to filter (optional)
FindJobChains(name string, start, limit int, asc bool, status ...string) ([]*JobChain, error)
// IterJobChains find job chains and iterate
// name: name to filter (optional)
// status: status to filter (optional)
IterJobChains(it func(*JobChain) error, name string, start, limit int, asc bool, status ...string) error
// CreateJobChain create a job chain
CreateJobChain(name, states string) (int64, error)
// UpcateJobChain update the job chain, ignore empty status, states
UpdateJobChain(cid int64, status string, states ...string) error
// DeleteJobChains delete job chains
DeleteJobChains(cids ...int64) (int64, error)
// CleanOutdatedJobChains delete outdated job chains
CleanOutdatedJobChains(before time.Time) (int64, error)
}
type JobLog ¶
type JobLog struct {
ID int64 `gorm:"not null;primaryKey;autoIncrement" json:"id,omitempty"`
JID int64 `gorm:"column:jid;not null;index:idx_job_logs_jid" json:"jid,omitempty"`
Time time.Time `gorm:"not null" json:"time,omitempty"`
Level string `gorm:"size:1;not null" json:"level,omitempty"`
Message string `gorm:"not null" json:"message,omitempty"`
}
type JobLogWriter ¶
type JobLogWriter struct {
log.BatchSupport
log.FilterSupport
// contains filtered or unexported fields
}
JobLogWriter implements log Writer Interface and writes messages to terminal.
func NewJobLogWriter ¶
func NewJobLogWriter(jmr JobManager, jid int64) *JobLogWriter
type JobManager ¶
type JobManager interface {
// CountJobLogs count job logs
CountJobLogs(jid int64, levels ...string) (int64, error)
// GetJobLogs get job logs
// set levels to ("I", "W", "E", "F") to filter DEBUG/TRACE logs
GetJobLogs(jid int64, minLid, maxLid int64, asc bool, limit int, levels ...string) ([]*JobLog, error)
// AddJobLogs append job logs
AddJobLogs([]*JobLog) error
// AddJobLog append a job log
AddJobLog(jid int64, time time.Time, level string, message string) error
// GetJob get a job
// cols: columns to select, if omit then select all columns (*)
GetJob(jid int64, cols ...string) (*Job, error)
// FindJob find a job
// name: name to filter (optional)
// status: status to filter (optional)
FindJob(name string, asc bool, status ...string) (*Job, error)
// FindJobs find jobs
// name: name to filter (optional)
// status: status to filter (optional)
FindJobs(name string, start, limit int, asc bool, status ...string) ([]*Job, error)
// IterJobs find jobs and iterate
// name: name to filter (optional)
// status: status to filter (optional)
IterJobs(it func(job *Job) error, name string, start, limit int, asc bool, status ...string) error
// AppendJob append a pendding job
AppendJob(cid int64, name, locale, param string) (int64, error)
// AbortJob abort the job
AbortJob(jid int64, reason string) error
// CancelJob cancel the job
CancelJob(jid int64, reason string) error
// FinishJob update job status to finished
FinishJob(jid int64) error
// CheckoutJob change job status from pending to running
CheckoutJob(jid, rid int64) error
// PinJob update the running job updated_at to now
PinJob(jid, rid int64) error
// SetJobState update the running job state
SetJobState(jid, rid int64, state string) error
// AddJobResult append result to the running job
AddJobResult(jid, rid int64, result string) error
// ReappendJobs reappend the interrupted runnings job to the pennding status
ReappendJobs(before time.Time) (int64, error)
// StartJobs start to run jobs
StartJobs(limit int, start func(*Job)) error
// DeleteJobs delete jobs
DeleteJobs(jids ...int64) (int64, int64, error)
// CleanOutdatedJobs delete outdated jobs
CleanOutdatedJobs(before time.Time) (int64, int64, error)
}
type JobRunner ¶
type JobRunner struct {
// contains filtered or unexported fields
}
func NewJobRunner ¶
func NewJobRunner(job *Job, jmr JobManager, logger ...log.Logger) *JobRunner
NewJobRunner create a JobRunner
func (*JobRunner) JobLogWriter ¶ added in v1.0.27
func (jr *JobRunner) JobLogWriter() *JobLogWriter
func (*JobRunner) JobManager ¶ added in v1.0.27
func (jr *JobRunner) JobManager() JobManager
Source Files
¶
Click to show internal directories.
Click to hide internal directories.