xjm

package
v1.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 8 Imported by: 5

Documentation

Index

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

func (j *Job) IsAborted() bool

func (*Job) IsCompleted

func (j *Job) IsCompleted() bool

func (*Job) IsPending

func (j *Job) IsPending() bool

func (*Job) IsRunning

func (j *Job) IsRunning() 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" 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"`
}

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.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

func (*JobLogWriter) Close

func (jlw *JobLogWriter) Close()

Close implementing method. empty.

func (*JobLogWriter) Flush

func (jlw *JobLogWriter) Flush()

Flush implementing method. empty.

func (*JobLogWriter) Write

func (jlw *JobLogWriter) Write(le *log.Event) (err error)

Write write message in console.

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

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, jnm string, jid, rid int64, 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) Checkout

func (jr *JobRunner) Checkout() error

func (*JobRunner) Complete

func (jr *JobRunner) Complete() error

func (*JobRunner) GetJob

func (jr *JobRunner) GetJob() (*Job, error)

func (*JobRunner) JobID

func (jr *JobRunner) JobID() int64

func (*JobRunner) JobName added in v1.0.17

func (jr *JobRunner) JobName() string

func (*JobRunner) Ping

func (jr *JobRunner) Ping() error

func (*JobRunner) RunnerID

func (jr *JobRunner) RunnerID() int64

func (*JobRunner) Running

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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