worker

package
v0.0.0-...-73c3907 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 33 Imported by: 0

README

Worker

Note: The default que GoQueQueue(github.com/tnclong/go-que) only supports postgres for now.

Documentation

Index

Constants

View Source
const (
	ActionJobInputParams = "worker_action_job_input_params"
	ActionJobCreate      = "worker_action_job_create"
	ActionJobResponse    = "worker_action_job_response"
	ActionJobClose       = "worker_action_job_close"
	ActionJobProgressing = "worker_action_job_progressing"
)
View Source
const (
	// JobStatusNew job status new
	JobStatusNew = "new"
	// JobStatusScheduled job status scheduled
	JobStatusScheduled = "scheduled"
	// JobStatusRunning job status running
	JobStatusRunning = "running"
	// JobStatusCancelled job status cancelled
	JobStatusCancelled = "cancelled"
	// JobStatusDone job status done
	JobStatusDone = "done"
	// JobStatusException job status exception
	JobStatusException = "exception"
	// JobStatusKilled job status killed
	JobStatusKilled = "killed"
)
View Source
const I18nWorkerKey i18n.ModuleKey = "I18nWorkerKey"
View Source
const (
	PermEdit = "perm_worker_edit"
)

examples:. permPolicy.On("*") permPolicy.On("workers:upload_posts")

Variables

View Source
var (
	DefaultOriginalPageContextHandler = func(ctx *web.EventContext) map[string]interface{} {
		return map[string]interface{}{
			"URL": ctx.R.Header.Get("Referer"),
		}
	}
)
View Source
var Messages_en_US = &Messages{
	StatusNew:                "New",
	StatusScheduled:          "Scheduled",
	StatusRunning:            "Running",
	StatusCancelled:          "Cancelled",
	StatusDone:               "Done",
	StatusException:          "Exception",
	StatusKilled:             "Killed",
	FilterTabAll:             "All Jobs",
	FilterTabRunning:         "Running",
	FilterTabScheduled:       "Scheduled",
	FilterTabDone:            "Done",
	FilterTabErrors:          "Errors",
	ActionCancelJob:          "Cancel Job",
	ActionAbortJob:           "Abort Job",
	ActionUpdateJob:          "Update Job",
	ActionRerunJob:           "Rerun Job",
	DetailTitleStatus:        "Status",
	DetailTitleLog:           "Log",
	NoticeJobCannotBeAborted: "This job cannot be aborted/canceled/updated due to its status change",
	NoticeJobWontBeExecuted:  "This job won't be executed due to code being deleted/modified",
	ScheduleTime:             "Schedule Time",
	DateTimePickerClearText:  "Clear",
	DateTimePickerOkText:     "OK",
	PleaseSelectJob:          "Please select job",
}
View Source
var Messages_zh_CN = &Messages{
	StatusNew:                "新建",
	StatusScheduled:          "计划",
	StatusRunning:            "运行中",
	StatusCancelled:          "取消",
	StatusDone:               "完成",
	StatusException:          "错误",
	StatusKilled:             "中止",
	FilterTabAll:             "全部",
	FilterTabRunning:         "运行中",
	FilterTabScheduled:       "计划",
	FilterTabDone:            "完成",
	FilterTabErrors:          "错误",
	ActionCancelJob:          "取消Job",
	ActionAbortJob:           "中止Job",
	ActionUpdateJob:          "更新Job",
	ActionRerunJob:           "重跑Job",
	DetailTitleStatus:        "状态",
	DetailTitleLog:           "日志",
	NoticeJobCannotBeAborted: "Job状态已经改变,不能被中止/取消/更新",
	NoticeJobWontBeExecuted:  "Job代码被删除/修改, 这个Job不会被执行",
	ScheduleTime:             "执行时间",
	DateTimePickerClearText:  "清空",
	DateTimePickerOkText:     "确定",
	PleaseSelectJob:          "请选择Job",
}

Functions

This section is empty.

Types

type ActionJobBuilder

type ActionJobBuilder struct {
	// contains filtered or unexported fields
}

func (*ActionJobBuilder) ContextHandler

func (action *ActionJobBuilder) ContextHandler(handler func(*web.EventContext) map[string]interface{}) *ActionJobBuilder

func (*ActionJobBuilder) Description

func (action *ActionJobBuilder) Description(description string) *ActionJobBuilder

func (*ActionJobBuilder) DisplayLog

func (action *ActionJobBuilder) DisplayLog(b bool) *ActionJobBuilder

func (ActionJobBuilder) GetParamsModelBuilder

func (action ActionJobBuilder) GetParamsModelBuilder() *presets.ModelBuilder

func (*ActionJobBuilder) Global

func (action *ActionJobBuilder) Global(b bool) *ActionJobBuilder

func (*ActionJobBuilder) Params

func (action *ActionJobBuilder) Params(params interface{}) *ActionJobBuilder

func (*ActionJobBuilder) ProgressingInterval

func (action *ActionJobBuilder) ProgressingInterval(interval int) *ActionJobBuilder

func (ActionJobBuilder) URL

func (action ActionJobBuilder) URL() string

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func New

func New(db *gorm.DB) *Builder

func NewWithQueue

func NewWithQueue(db *gorm.DB, q Queue) *Builder

func (*Builder) ActionJob

func (b *Builder) ActionJob(jobName string, model *presets.ModelBuilder, hander JobHandler) *ActionJobBuilder

func (*Builder) Activity

func (b *Builder) Activity(ab *activity.ActivityBuilder) *Builder

Activity sets Activity Builder to log activities

func (*Builder) Configure

func (b *Builder) Configure(pb *presets.Builder) *presets.ModelBuilder

func (*Builder) GetCurrentUserIDFunc

func (b *Builder) GetCurrentUserIDFunc(f func(r *http.Request) string) *Builder

func (*Builder) Listen

func (b *Builder) Listen()

func (*Builder) NewJob

func (b *Builder) NewJob(name string) *JobBuilder

func (*Builder) Queue

func (b *Builder) Queue(q Queue) *Builder

default queue is go-que queue

type GoQueError

type GoQueError struct {
	gorm.Model
	Error string
}

type JobBuilder

type JobBuilder struct {
	// contains filtered or unexported fields
}

func (*JobBuilder) ContextHandler

func (jb *JobBuilder) ContextHandler(handler func(*web.EventContext) map[string]interface{}) *JobBuilder

func (*JobBuilder) GetResourceBuilder

func (jb *JobBuilder) GetResourceBuilder() *presets.ModelBuilder

func (*JobBuilder) Handler

func (jb *JobBuilder) Handler(h JobHandler) *JobBuilder

func (*JobBuilder) Resource

func (jb *JobBuilder) Resource(r interface{}) *JobBuilder

r should be ptr to struct

type JobHandler

type JobHandler func(context.Context, QorJobInterface) error

type JobInfo

type JobInfo struct {
	JobID    string
	JobName  string
	Operator string
	Argument interface{}
	Context  map[string]interface{}
}

type Messages

type Messages struct {
	StatusNew                string
	StatusScheduled          string
	StatusRunning            string
	StatusCancelled          string
	StatusDone               string
	StatusException          string
	StatusKilled             string
	FilterTabAll             string
	FilterTabRunning         string
	FilterTabScheduled       string
	FilterTabDone            string
	FilterTabErrors          string
	ActionCancelJob          string
	ActionAbortJob           string
	ActionUpdateJob          string
	ActionRerunJob           string
	DetailTitleStatus        string
	DetailTitleLog           string
	NoticeJobCannotBeAborted string
	NoticeJobWontBeExecuted  string
	ScheduleTime             string
	DateTimePickerClearText  string
	DateTimePickerOkText     string
	PleaseSelectJob          string
}

type QorJob

type QorJob struct {
	gorm.Model

	Job    string
	Status string      `sql:"default:'new'"`
	Args   interface{} `sql:"-" gorm:"-"`
}

type QorJobDefinition

type QorJobDefinition struct {
	Name    string
	Handler JobHandler
}

type QorJobInstance

type QorJobInstance struct {
	gorm.Model

	QorJobID uint `gorm:"index"`

	Operator string

	Job     string
	Status  string `sql:"default:'new'"`
	Args    string
	Context string

	Progress     uint
	ProgressText string
	// contains filtered or unexported fields
}

func (*QorJobInstance) AddLog

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

func (*QorJobInstance) AddLogf

func (job *QorJobInstance) AddLogf(format string, a ...interface{}) error

func (*QorJobInstance) FetchAndSetStatus

func (job *QorJobInstance) FetchAndSetStatus() (string, error)

func (*QorJobInstance) GetHandler

func (job *QorJobInstance) GetHandler() JobHandler

func (*QorJobInstance) GetJobInfo

func (job *QorJobInstance) GetJobInfo() (ji *JobInfo, err error)

func (*QorJobInstance) GetStatus

func (job *QorJobInstance) GetStatus() string

func (*QorJobInstance) SetProgress

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

func (*QorJobInstance) SetProgressText

func (job *QorJobInstance) SetProgressText(s string) error

func (*QorJobInstance) SetStatus

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

func (*QorJobInstance) StartRefresh

func (job *QorJobInstance) StartRefresh()

func (*QorJobInstance) StopRefresh

func (job *QorJobInstance) StopRefresh()

type QorJobInterface

type QorJobInterface interface {
	GetJobInfo() (*JobInfo, error)
	SetProgress(uint) error
	SetProgressText(string) error
	AddLog(string) error
	AddLogf(format string, a ...interface{}) error
}

for job handler

type QorJobLog

type QorJobLog struct {
	ID        uint      `gorm:"primarykey"`
	CreatedAt time.Time `gorm:"index"`

	QorJobInstanceID uint `gorm:"index"`
	Log              string
}

type QueJobInterface

type QueJobInterface interface {
	QorJobInterface

	GetStatus() string
	FetchAndSetStatus() (string, error)
	SetStatus(string) error

	StartRefresh()
	StopRefresh()

	GetHandler() JobHandler
}

type Queue

type Queue interface {
	Add(QueJobInterface) error
	Kill(QueJobInterface) error
	Remove(QueJobInterface) error
	Listen(jobDefs []*QorJobDefinition, getJob func(qorJobID uint) (QueJobInterface, error)) error
}

func NewCronQueue

func NewCronQueue() Queue

NewCronQueue initialize a Cron queue

func NewGoQueQueue

func NewGoQueQueue(db *gorm.DB) Queue

type Schedule

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

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

GetScheduleTime get scheduled time

func (*Schedule) SetScheduleTime

func (schedule *Schedule) SetScheduleTime(t *time.Time)

type Scheduler

type Scheduler interface {
	GetScheduleTime() *time.Time
	SetScheduleTime(t *time.Time)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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