xjm

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobStatusAborted  = "A"
	JobStatusCanceled = "C"
	JobStatusFinished = "F"
	JobStatusPending  = "P"
	JobStatusRunning  = "R"
)

Variables

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 Decode

func Decode(p string, v any) error

func Encode

func Encode(v any) (string, error)

func MustDecode added in v1.0.17

func MustDecode(p string, v any)

func MustEncode added in v1.0.17

func MustEncode(v any) string

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) IsAborted

func (j *Job) IsAborted() bool

func (*Job) IsCanceled added in v1.0.27

func (j *Job) IsCanceled() bool

func (*Job) IsDone added in v1.0.27

func (j *Job) IsDone() bool

func (*Job) IsFinished added in v1.0.27

func (j *Job) IsFinished() bool

func (*Job) IsPending

func (j *Job) IsPending() bool

func (*Job) IsRunning

func (j *Job) IsRunning() bool

func (*Job) IsUndone added in v1.0.27

func (j *Job) IsUndone() bool

func (*Job) String

func (j *Job) String() string

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) IsAborted added in v1.0.27

func (jc *JobChain) IsAborted() bool

func (*JobChain) IsCanceled added in v1.0.27

func (jc *JobChain) IsCanceled() bool

func (*JobChain) IsDone added in v1.0.27

func (jc *JobChain) IsDone() bool

func (*JobChain) IsFinished added in v1.0.27

func (jc *JobChain) IsFinished() bool

func (*JobChain) IsPending added in v1.0.27

func (jc *JobChain) IsPending() bool

func (*JobChain) IsRunning added in v1.0.27

func (jc *JobChain) IsRunning() bool

func (*JobChain) IsUndone added in v1.0.27

func (jc *JobChain) IsUndone() bool

func (*JobChain) String added in v1.0.17

func (jc *JobChain) String() string

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"`
}

func (*JobLog) String

func (jl *JobLog) String() string

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

func (*JobLogWriter) Close

func (jw *JobLogWriter) Close()

Close flush cached log events

func (*JobLogWriter) Flush

func (jw *JobLogWriter) Flush()

Flush flush cached log events

func (*JobLogWriter) Write

func (jw *JobLogWriter) Write(le *log.Event)

Write write log event.

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) Abort

func (jr *JobRunner) Abort(reason string) error

func (*JobRunner) AddResult added in v1.0.17

func (jr *JobRunner) AddResult(result string) error

func (*JobRunner) Cancel added in v1.0.27

func (jr *JobRunner) Cancel(reason string) error

func (*JobRunner) ChainID added in v1.0.27

func (jr *JobRunner) ChainID() int64

func (*JobRunner) Checkout

func (jr *JobRunner) Checkout() error

func (*JobRunner) Finish added in v1.0.27

func (jr *JobRunner) Finish() error

func (*JobRunner) GetJob

func (jr *JobRunner) GetJob(cols ...string) (*Job, error)

func (*JobRunner) JobID

func (jr *JobRunner) JobID() int64

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

func (*JobRunner) JobName added in v1.0.17

func (jr *JobRunner) JobName() string

func (*JobRunner) JobParam added in v1.0.27

func (jr *JobRunner) JobParam() string

func (*JobRunner) Locale added in v1.0.27

func (jr *JobRunner) Locale() string

func (*JobRunner) Log

func (jr *JobRunner) Log() *log.Log

func (*JobRunner) Pin added in v1.0.27

func (jr *JobRunner) Pin() error

func (*JobRunner) RunnerID

func (jr *JobRunner) RunnerID() int64

func (*JobRunner) Running

func (jr *JobRunner) Running(ctx context.Context, getTimeout, pinTimeout time.Duration) error

func (*JobRunner) SetState added in v1.0.27

func (jr *JobRunner) SetState(state string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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