Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(p string, v any) error
- func Encode(v any) string
- type Job
- type JobLog
- type JobLogWriter
- type JobManager
- type JobRunner
- func (jr *JobRunner) Abort(reason string) error
- func (jr *JobRunner) Checkout() error
- func (jr *JobRunner) Complete(result string) error
- func (jr *JobRunner) GetJob() (*Job, error)
- func (jr *JobRunner) JobID() int64
- func (jr *JobRunner) Ping() error
- func (jr *JobRunner) PingAborted() bool
- func (jr *JobRunner) RunnerID() int64
- func (jr *JobRunner) Running(state string) error
Constants ¶
View Source
const ( JobStatusAborted = "A" JobStatusCompleted = "C" JobStatusPending = "P" JobStatusRunning = "R" )
Variables ¶
View Source
var ( JobPendingRunning = []string{JobStatusPending, JobStatusRunning} JobAbortedCompleted = []string{JobStatusAborted, JobStatusCompleted} )
View Source
var ( ErrJobAborted = errors.New("job aborted") ErrJobCompleted = errors.New("job completed") ErrJobCheckout = errors.New("job checkout failed: job running or missing") ErrJobExisting = errors.New("job existing") ErrJobMissing = errors.New("job missing") ErrJobPing = errors.New("job ping failed") )
Functions ¶
Types ¶
type Job ¶
type Job struct { ID int64 `gorm:"not null;primaryKey;autoIncrement" uri:"id" form:"id" json:"id,omitempty"` RID int64 `gorm:"column:rid;not null" form:"rid" json:"rid,omitempty"` // job runner id Name string `gorm:"size:250;not null;index" json:"name,omitempty"` Status string `gorm:"size:1;not null" form:"status" 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:"<-:create;not null" json:"created_at,omitempty"` UpdatedAt time.Time `gorm:"not null" json:"updated_at,omitempty"` }
func (*Job) IsCompleted ¶
type JobLog ¶
type JobLog struct { ID int64 `gorm:"not null;primaryKey;autoIncrement" uri:"id" form:"id" json:"id,omitempty"` JID int64 `gorm:"column:jid;not null;index:idx_job_logs_jid" uri:"jid" form:"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 // GetJob get job detail GetJob(jid int64) (*Job, error) // FindJob find the latest job by name. // status: status to filter. FindJob(name string, asc bool, status ...string) (*Job, error) // FindJobs find jobs by name. // status: status to filter. FindJobs(name string, start, limit int, asc bool, status ...string) ([]*Job, error) // IterJobs find jobs by name and iterate. // status: status to filter. 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 complete the job CompleteJob(jid int64, result string) error // CheckoutJob checkout the job to the running status CheckoutJob(jid, rid int64) error // PingJob update the job updated_at to now PingJob(jid, rid int64) error // RunningJob update the running job state RunningJob(jid, rid int64, state 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 // CleanOutdatedJobs delete outdated jobs CleanOutdatedJobs(before time.Time) (int64, int64, error) }
type JobRunner ¶
type JobRunner struct { Log *log.Log PingAfter time.Duration // Ping after duration // contains filtered or unexported fields }
func NewJobRunner ¶
func NewJobRunner(jmr JobManager, jid, rid int64, logger ...log.Logger) *JobRunner
NewJobRunner create a JobRunner
func (*JobRunner) PingAborted ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.