Documentation
¶
Index ¶
- Constants
- Variables
- func ExitError(err error)
- func ExitErrorFmt(tempate string, err error, args ...interface{})
- func JobUID(site interface{}, job interface{}) string
- type CLIArgs
- type Config
- type Cron
- type Job
- type Plugin
- type QorJob
- func (job *QorJob) AddLog(log string) error
- func (job *QorJob) AddResultsRow(cells ...TableCell) error
- func (job *QorJob) AfterScan(db *aorm.DB)
- func (job *QorJob) GetArgument() interface{}
- func (job *QorJob) GetID() string
- func (job *QorJob) GetJob() *Job
- func (job *QorJob) GetJobID() bid.BID
- func (job *QorJob) GetJobKey() string
- func (job *QorJob) GetJobName() string
- func (job *QorJob) GetLogs() []string
- func (job *QorJob) GetName() 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) GetStatusUpdatedAt() *time.Time
- func (job *QorJob) Init(site *core.Site)
- 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) Site() *core.Site
- func (job *QorJob) UID() string
- type QorJobInterface
- type Queue
- type ResultsTable
- type Schedule
- type Scheduler
- type TableCell
- type Worker
- func (worker *Worker) AddJob(qorJob QorJobInterface) error
- func (worker *Worker) ConfigureResource(res resource.Resourcer)
- func (worker *Worker) ConfigureResourceBeforeInitialize(res resource.Resourcer)
- func (worker *Worker) CreateCommand() *cobra.Command
- func (worker *Worker) GetJob(site *core.Site, jobID aorm.ID) (QorJobInterface, error)
- func (worker *Worker) GetRegisteredJob(name string) *Job
- func (worker *Worker) KillJob(site *core.Site, jobID aorm.ID) error
- func (worker *Worker) ParseJobUID(uid string) (site *core.Site, jobID aorm.ID, err error)
- func (worker *Worker) RegisterJob(job *Job) error
- func (worker *Worker) RemoveJob(site *core.Site, jobID aorm.ID) error
- func (worker *Worker) RunJob(site *core.Site, jobID aorm.ID) error
- func (worker *Worker) SetQueue(queue Queue)
- func (worker *Worker) ToDB(db *aorm.DB) *aorm.DB
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 ¶
var ( PREFIX = path_helpers.GetCalledDir() I18NGROUP = i18nmod.PkgToGroup(PREFIX) )
Functions ¶
func ExitErrorFmt ¶
func ExitErrorFmt(tempate string, err error, args ...interface{})
Types ¶
type Config ¶
type Config struct {
CLIArgs *CLIArgs
Sites *core.SitesRegister
AdminSite string
Queue Queue
Job QorJobInterface
Admin *admin.Admin
}
Config worker config
type Cron ¶
type Cron struct {
CLIArgs CLIArgs
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 {
Key string
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 Plugin ¶
type Plugin struct {
db.DBNames
plug.EventDispatcher
WorkerKey string
}
func (*Plugin) OnRegister ¶
func (p *Plugin) OnRegister()
func (*Plugin) RequireOptions ¶
type QorJob ¶
type QorJob struct {
aorm.AuditedModel
StatusUpdatedAt *time.Time
Name string
Status string `sql:"default:'new'"`
Progress uint
ProgressText string
Log string `sql:"size:65532"`
ResultsTable ResultsTable `sql:"size:65532"`
SiteName string
Job *Job `sql:"-"`
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) GetStatusUpdatedAt ¶
func (*QorJob) SetProgress ¶
SetProgress set qor job's progress
func (*QorJob) SetProgressText ¶
SetProgressText set qor job's progress text
type QorJobInterface ¶
type QorJobInterface interface {
Site() *core.Site
UID() string
GetJobID() bid.BID
GetJobKey() string
GetJobName() string
GetName() string
GetStatus() string
GetStatusUpdatedAt() *time.Time
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
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 map[string]*Job
// contains filtered or unexported fields
}
Worker worker definition
func WorkerFromDB ¶
func (*Worker) AddJob ¶
func (worker *Worker) AddJob(qorJob QorJobInterface) error
AddJob add job to worker
func (*Worker) ConfigureResource ¶
ConfigureResource a method used to config Worker for qor admin
func (*Worker) ConfigureResourceBeforeInitialize ¶
ConfigureQorResourceBeforeInitialize a method used to config Worker for qor admin
func (*Worker) CreateCommand ¶
func (*Worker) GetRegisteredJob ¶
GetRegisteredJob register a job into Worker
func (*Worker) ParseJobUID ¶
func (*Worker) RegisterJob ¶
RegisterJob register a job into Worker