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) Checkout() error
- func (jr *JobRunner) Complete() error
- func (jr *JobRunner) GetJob() (*Job, error)
- func (jr *JobRunner) JobID() int64
- func (jr *JobRunner) JobName() string
- func (jr *JobRunner) Ping() error
- func (jr *JobRunner) RunnerID() int64
- func (jr *JobRunner) Running(state string) error
Constants ¶
View Source
const ( JobStatusAborted = "A" JobStatusCompleted = "C" JobStatusPending = "P" JobStatusRunning = "R" )
View Source
const ( JobChainAborted = "A" JobChainCompleted = "C" JobChainPending = "P" JobChainRunning = "R" )
Variables ¶
View Source
var ( JobPendingRunning = []string{JobStatusPending, JobStatusRunning} JobAbortedCompleted = []string{JobStatusAborted, JobStatusCompleted} )
View Source
var ( ErrJobAborted = errors.New("job aborted") // indicates this job status is Aborted, returns by PingJob ErrJobComplete = errors.New("job complete") // indicates this job is finished, should update job status to Completed ErrJobCheckout = errors.New("job checkout failed: job running or missing") ErrJobExisting = errors.New("job existing") ErrJobMissing = errors.New("job missing") )
View Source
var ( JobChainPendingRunning = []string{JobChainPending, JobChainRunning} JobChainAbortedCompleted = []string{JobChainAborted, JobChainCompleted} )
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() )
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"` RID int64 `gorm:"column:rid;not null" json:"rid,omitempty"` Name string `gorm:"size:250;not null;index" json:"name,omitempty"` Status string `gorm:"size:1;not null" json:"status,omitempty"` File string `gorm:"not null" json:"file,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) IsCompleted ¶
type JobChain ¶ added in v1.0.17
type JobChain struct { ID int64 `gorm:"not null;primaryKey;autoIncrement" form:"id" json:"id"` Name string `gorm:"size:250;not null" form:"title,strip" json:"title"` Status string `gorm:"size:1;not null" form:"status,strip" json:"status"` States string `gorm:"not null" form:"states" json:"states,omitempty"` CreatedAt time.Time `gorm:"not null;<-:create" json:"created_at"` UpdatedAt time.Time `gorm:"not null" json:"updated_at"` }
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.LogFilter log.BatchWriter // 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, min, max 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 GetJob(jid int64) (*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(name, file, param string) (int64, error) // AbortJob abort the job AbortJob(jid int64, reason string) error // CompleteJob update job status to completed CompleteJob(jid int64) error // CheckoutJob change job status from pending to running CheckoutJob(jid, rid int64) error // PingJob update the job updated_at to now PingJob(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, run func(*Job)) error // DeleteJobs delete jobs DeleteJobs(jids ...int64) (int64, int64, error) // CleanOutdatedJobs delete outdated jobs CleanOutdatedJobs(before time.Time) (int64, int64, error) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.