Documentation
¶
Index ¶
- Constants
- type Config
- type Cron
- type Job
- type QorJob
- func (job *QorJob) AddLog(log string) error
- func (job *QorJob) AddResultsRow(cells ...TableCell) error
- func (job *QorJob) GetArgument() interface{}
- func (job *QorJob) GetJob() *Job
- func (job *QorJob) GetJobID() string
- func (job *QorJob) GetJobName() string
- func (job *QorJob) GetLogs() []string
- func (job *QorJob) GetProgress() uint
- func (job *QorJob) GetProgressText() string
- func (job *QorJob) GetResultsTable() ResultsTable
- func (job *QorJob) GetSerializableArgumentResource() *admin.Resource
- func (job *QorJob) GetStatus() string
- func (job *QorJob) SetJob(j *Job)
- func (job *QorJob) SetProgress(progress uint) error
- func (job *QorJob) SetProgressText(str string) error
- func (job *QorJob) SetStatus(status string) error
- func (job *QorJob) StartReferesh()
- func (job *QorJob) StopReferesh()
- type QorJobInterface
- type Queue
- type ResultsTable
- type Schedule
- type Scheduler
- type TableCell
- type Worker
- func (worker *Worker) AddJob(qorJob QorJobInterface) error
- func (worker *Worker) ConfigureQorResource(res resource.Resourcer)
- func (worker *Worker) ConfigureQorResourceBeforeInitialize(res resource.Resourcer)
- func (worker *Worker) GetJob(jobID string) (QorJobInterface, error)
- func (worker *Worker) GetRegisteredJob(name string) *Job
- func (worker *Worker) KillJob(jobID string) error
- func (worker *Worker) RegisterJob(job *Job) error
- func (worker *Worker) RemoveJob(jobID string) error
- func (worker *Worker) RunJob(jobID string) error
- func (worker *Worker) SetQueue(queue Queue)
Constants ¶
const ( // JobStatusScheduled job status scheduled JobStatusScheduled = "scheduled" // JobStatusCancelled job status cancelled JobStatusCancelled = "cancelled" // JobStatusNew job status new JobStatusNew = "new" // JobStatusRunning job status running JobStatusRunning = "running" // JobStatusDone job status done JobStatusDone = "done" // JobStatusException job status exception JobStatusException = "exception" // JobStatusKilled job status killed JobStatusKilled = "killed" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Queue Queue
Job QorJobInterface
Admin *admin.Admin
}
Config worker config
type Cron ¶
type Cron struct {
Jobs []*cronJob
CronJobs []string
// contains filtered or unexported fields
}
Cron implemented a worker Queue based on cronjob
func (*Cron) Kill ¶
func (cron *Cron) Kill(job QorJobInterface) (err error)
Kill a job from cron queue
func (*Cron) Remove ¶
func (cron *Cron) Remove(job QorJobInterface) error
Remove a job from cron queue
type Job ¶
type Job struct {
Name string
Group string
Handler func(interface{}, QorJobInterface) error
Permission *roles.Permission
Queue Queue
Resource *admin.Resource
Worker *Worker
}
Job is a struct that hold Qor Job definations
func (Job) HasPermission ¶
type QorJob ¶
type QorJob struct {
gorm.Model
Status string `sql:"default:'new'"`
Progress uint
ProgressText string
Log string `sql:"size:65532"`
ResultsTable ResultsTable `sql:"size:65532"`
// Add `valid:"-"“ to make the QorJob work well with qor/validations
// When the qor/validations auto exec the validate struct callback we get error
// runtime: goroutine stack exceeds 1000000000-byte limit
// fatal error: stack overflow
Job *Job `sql:"-" valid:"-"`
audited.AuditedModel
serializable_meta.SerializableMeta
// contains filtered or unexported fields
}
QorJob predefined qor job struct, which will be used for Worker, if it doesn't include a job resource
func (*QorJob) AddResultsRow ¶
AddResultsRow add a row of process results to a job
func (*QorJob) GetArgument ¶
func (job *QorJob) GetArgument() interface{}
GetArgument get job's argument
func (*QorJob) GetJobName ¶
GetJobName get job's name from a qor job
func (*QorJob) GetProgress ¶
GetProgress get qor job's progress
func (*QorJob) GetProgressText ¶
GetProgressText get qor job's progress text
func (*QorJob) GetResultsTable ¶
func (job *QorJob) GetResultsTable() ResultsTable
GetResultsTable get the job's process logs
func (*QorJob) GetSerializableArgumentResource ¶
GetSerializableArgumentResource get job's argument's resource
func (*QorJob) SetProgress ¶
SetProgress set qor job's progress
func (*QorJob) SetProgressText ¶
SetProgressText set qor job's progress text
func (*QorJob) StartReferesh ¶
func (job *QorJob) StartReferesh()
func (*QorJob) StopReferesh ¶
func (job *QorJob) StopReferesh()
type QorJobInterface ¶
type QorJobInterface interface {
GetJobID() string
GetJobName() string
GetStatus() string
SetStatus(string) error
GetJob() *Job
SetJob(*Job)
GetProgress() uint
SetProgress(uint) error
GetProgressText() string
SetProgressText(string) error
GetLogs() []string
AddLog(string) error
GetResultsTable() ResultsTable
AddResultsRow(...TableCell) error
StartReferesh()
StopReferesh()
GetArgument() interface{}
serializable_meta.SerializableMetaInterface
}
QorJobInterface is a interface, defined methods that needs for a qor job
type Queue ¶
type Queue interface {
Add(QorJobInterface) error
Run(QorJobInterface) error
Kill(QorJobInterface) error
Remove(QorJobInterface) error
}
Queue is an interface defined methods need for a job queue
type ResultsTable ¶
type ResultsTable struct {
Name string `json:"-"` // only used for generate string column in database
TableCells [][]TableCell
}
ResultsTable is a struct, including importing/exporting results
func (*ResultsTable) Scan ¶
func (resultsTable *ResultsTable) Scan(data interface{}) error
Scan used to scan value from database into itself
type Schedule ¶
Schedule could be embedded as job argument, then the job will get run as scheduled feature
func (Schedule) GetScheduleTime ¶
GetScheduleTime get scheduled time
type Worker ¶
type Worker struct {
*Config
JobResource *admin.Resource
Jobs []*Job
// contains filtered or unexported fields
}
Worker worker definition
func (*Worker) AddJob ¶
func (worker *Worker) AddJob(qorJob QorJobInterface) error
AddJob add job to worker
func (*Worker) ConfigureQorResource ¶
ConfigureQorResource a method used to config Worker for qor admin
func (*Worker) ConfigureQorResourceBeforeInitialize ¶
ConfigureQorResourceBeforeInitialize a method used to config Worker for qor admin
func (*Worker) GetJob ¶
func (worker *Worker) GetJob(jobID string) (QorJobInterface, error)
GetJob get job with id
func (*Worker) GetRegisteredJob ¶
GetRegisteredJob register a job into Worker
func (*Worker) RegisterJob ¶
RegisterJob register a job into Worker