worker: Index | Files

package worker

import ""


Package Files

controller.go cron.go job.go qor_job.go queue.go scheduler.go worker.go


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"

type Config Uses

type Config struct {
    Queue Queue
    Job   QorJobInterface
    Admin *admin.Admin

Config worker config

type Cron Uses

type Cron struct {
    Jobs     []*cronJob
    CronJobs []string
    // contains filtered or unexported fields

Cron implemented a worker Queue based on cronjob

func NewCronQueue Uses

func NewCronQueue() *Cron

NewCronQueue initialize a Cron queue

func (*Cron) Add Uses

func (cron *Cron) Add(job QorJobInterface) (err error)

Add a job to cron queue

func (*Cron) Kill Uses

func (cron *Cron) Kill(job QorJobInterface) (err error)

Kill a job from cron queue

func (*Cron) Remove Uses

func (cron *Cron) Remove(job QorJobInterface) error

Remove a job from cron queue

func (*Cron) Run Uses

func (cron *Cron) Run(qorJob QorJobInterface) error

Run a job from cron queue

type Job Uses

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) GetQueue Uses

func (job *Job) GetQueue() Queue

GetQueue get defined job's queue

func (Job) HasPermission Uses

func (job Job) HasPermission(mode roles.PermissionMode, context *qor.Context) bool

func (*Job) NewStruct Uses

func (job *Job) NewStruct() interface{}

NewStruct initialize job struct

type QorJob Uses

type QorJob struct {
    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:"-"`

    // 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) AddLog Uses

func (job *QorJob) AddLog(log string) error

AddLog add a log to qor job

func (*QorJob) AddResultsRow Uses

func (job *QorJob) AddResultsRow(cells ...TableCell) error

AddResultsRow add a row of process results to a job

func (*QorJob) GetArgument Uses

func (job *QorJob) GetArgument() interface{}

GetArgument get job's argument

func (*QorJob) GetJob Uses

func (job *QorJob) GetJob() *Job

GetJob get predefined job for a qor job instance

func (*QorJob) GetJobID Uses

func (job *QorJob) GetJobID() string

GetJobID get job's ID from a qor job

func (*QorJob) GetJobName Uses

func (job *QorJob) GetJobName() string

GetJobName get job's name from a qor job

func (*QorJob) GetLogs Uses

func (job *QorJob) GetLogs() []string

GetLogs get qor job's logs

func (*QorJob) GetProgress Uses

func (job *QorJob) GetProgress() uint

GetProgress get qor job's progress

func (*QorJob) GetProgressText Uses

func (job *QorJob) GetProgressText() string

GetProgressText get qor job's progress text

func (*QorJob) GetResultsTable Uses

func (job *QorJob) GetResultsTable() ResultsTable

GetResultsTable get the job's process logs

func (*QorJob) GetSerializableArgumentResource Uses

func (job *QorJob) GetSerializableArgumentResource() *admin.Resource

GetSerializableArgumentResource get job's argument's resource

func (*QorJob) GetStatus Uses

func (job *QorJob) GetStatus() string

GetStatus get job's status from a qor job

func (*QorJob) SetJob Uses

func (job *QorJob) SetJob(j *Job)

SetJob set `Job` for a qor job instance

func (*QorJob) SetProgress Uses

func (job *QorJob) SetProgress(progress uint) error

SetProgress set qor job's progress

func (*QorJob) SetProgressText Uses

func (job *QorJob) SetProgressText(str string) error

SetProgressText set qor job's progress text

func (*QorJob) SetStatus Uses

func (job *QorJob) SetStatus(status string) error

SetStatus set job's status to a qor job instance

func (*QorJob) StartReferesh Uses

func (job *QorJob) StartReferesh()

func (*QorJob) StopReferesh Uses

func (job *QorJob) StopReferesh()

type QorJobInterface Uses

type QorJobInterface interface {
    GetJobID() string
    GetJobName() string
    GetStatus() string
    SetStatus(string) error
    GetJob() *Job

    GetProgress() uint
    SetProgress(uint) error
    GetProgressText() string
    SetProgressText(string) error
    GetLogs() []string
    AddLog(string) error
    GetResultsTable() ResultsTable
    AddResultsRow(...TableCell) error


    GetArgument() interface{}

QorJobInterface is a interface, defined methods that needs for a qor job

type Queue Uses

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 Uses

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 Uses

func (resultsTable *ResultsTable) Scan(data interface{}) error

Scan used to scan value from database into itself

func (ResultsTable) Value Uses

func (resultsTable ResultsTable) Value() (driver.Value, error)

Value used to read value from itself and save it into databae

type Schedule Uses

type Schedule struct {
    ScheduleTime *time.Time

Schedule could be embedded as job argument, then the job will get run as scheduled feature

func (Schedule) GetScheduleTime Uses

func (schedule Schedule) GetScheduleTime() *time.Time

GetScheduleTime get scheduled time

type Scheduler Uses

type Scheduler interface {
    GetScheduleTime() *time.Time

Scheduler is a interface, for job used to `GetScheduleTime`

type TableCell Uses

type TableCell struct {
    Value string
    Error string

TableCell including Value, Error for a data cell

type Worker Uses

type Worker struct {
    JobResource *admin.Resource
    Jobs        []*Job
    // contains filtered or unexported fields

Worker worker definition

func New Uses

func New(config ...*Config) *Worker

New create Worker with Config

func (*Worker) AddJob Uses

func (worker *Worker) AddJob(qorJob QorJobInterface) error

AddJob add job to worker

func (*Worker) ConfigureQorResource Uses

func (worker *Worker) ConfigureQorResource(res resource.Resourcer)

ConfigureQorResource a method used to config Worker for qor admin

func (*Worker) ConfigureQorResourceBeforeInitialize Uses

func (worker *Worker) ConfigureQorResourceBeforeInitialize(res resource.Resourcer)

ConfigureQorResourceBeforeInitialize a method used to config Worker for qor admin

func (*Worker) GetJob Uses

func (worker *Worker) GetJob(jobID string) (QorJobInterface, error)

GetJob get job with id

func (*Worker) GetRegisteredJob Uses

func (worker *Worker) GetRegisteredJob(name string) *Job

GetRegisteredJob register a job into Worker

func (*Worker) KillJob Uses

func (worker *Worker) KillJob(jobID string) error

KillJob kill job with job id

func (*Worker) RegisterJob Uses

func (worker *Worker) RegisterJob(job *Job) error

RegisterJob register a job into Worker

func (*Worker) RemoveJob Uses

func (worker *Worker) RemoveJob(jobID string) error

RemoveJob remove job with job id

func (*Worker) RunJob Uses

func (worker *Worker) RunJob(jobID string) error

RunJob run job with job id

func (*Worker) SetQueue Uses

func (worker *Worker) SetQueue(queue Queue)

SetQueue set worker's queue

Package worker imports 26 packages (graph) and is imported by 18 packages. Updated 2019-08-07. Refresh now. Tools for package owners.