Documentation
¶
Index ¶
Constants ¶
View Source
const ContextJobKey = "job-key"
View Source
const ContextQueueKey = "queue-key"
View Source
const MaxTime int64 = 9223372036854775807
Variables ¶
View Source
var JobError = joberror{ INVALID_JD: errors.New("invalid job description"), INVALID_JOB: errors.New("invalid job"), INVALID_WORKER: errors.New("invalid worker"), INVALID_PL: errors.New("invalid production line"), NOT_FOUND: errors.New("not found"), TERMINATING: errors.New("terminating"), DUPLICATE_JOB: errors.New("duplicate job"), }
View Source
var JobStatus = jobstatus{
INIT: "init",
PROCESSING: "processing",
RETRY: "retry",
ERROR: "error",
MAX_RETRY: "max_retry",
DONE: "done",
}
Functions ¶
This section is empty.
Types ¶
type Foreman ¶
type Foreman interface {
//AddWorker add a worker function for handler
AddWorker(title string, worker HandlerFunc, midl ...MiddlewareFunc) error
//AddJobTransaction add a new job to the queue
AddJobTransaction(ctx context.Context, job *Job) error
//AddJob add a new job to the queue without context, dont recommend but handy for multiple context
AddJob(job *Job) error
//AddJobWithSchedule add a new job to the queue to run at a schedule
AddJobWithSchedule(ctx context.Context, job *Job, runat int64) error
//Serve start the worker service
Serve() error
//Strike graceful shutdown service. Reject new jobs and wait for running one to finish. Force kill at TTL.
Strike(ttl int) error // ttl in seconds
//AddMiddleware add global middleware, order of adding matters
AddMiddleware(midl ...MiddlewareFunc)
//GetCounter return worker counter for debug purpose
GetCounter() int
}
func NewForeman ¶
func NewForeman(config *QueueConfig, store JobStorage, logger Logger) Foreman
type Governor ¶
type Governor interface {
AddJob(string)
DelJob(string)
NoJob()
Spawn() (bool, []string)
GetCounter() int
}
func NewLocalOndemandGovernor ¶
func NewLocalOndemandGovernor(max, min, maxworker int, jd map[string]JobDescription) Governor
OndemandGovernor ondemand governor
type HandlerFunc ¶
type Job ¶
type Job struct {
ID string `mapstructure:"id" yaml:"id" json:"id"`
JobID string `mapstructure:"job_id" yaml:"job_id" json:"job_id"`
Title string `mapstructure:"title" yaml:"title" json:"title"`
Payload string `mapstructure:"payload" yaml:"payload" json:"payload"`
Try int `mapstructure:"try" yaml:"try" json:"try"`
Priority int `mapstructure:"priority" yaml:"priority" json:"priority"`
Status string `mapstructure:"status" yaml:"status" json:"status"`
Result string `yaml:"result" mapstructure:"result" json:"result"`
Message string `yaml:"message" mapstructure:"message" json:"message"`
UpdatedAt int64 `yaml:"updated_at" mapstructure:"updated_at" json:"updated_at"`
}
type JobDescription ¶
type JobDescription struct {
Title string `mapstructure:"title" yaml:"title" json:"title"`
TTL int `mapstructure:"ttl" yaml:"ttl" json:"ttl"` // seconds
Concurrent int `mapstructure:"concurrent" yaml:"concurrent" json:"concurrent"` // 0 is invalid
Priority int `mapstructure:"priority" yaml:"priority" json:"priority"` // 0 is invalid here, 1 is highest
MaxRetry int `mapstructure:"max_retry" yaml:"max_retry" json:"max_retry"` // number of retry
Secure bool `mapstructure:"secure" yaml:"secure" json:"secure"`
}
Config models
type JobStorage ¶
type JobStorage interface {
CheckDuplicateJob(job Job) error
CreateJob(ctx context.Context, job Job) error
GetAndLockAvailableJob(jd map[string]JobDescription, ignorelist ...string) (*Job, error)
UpdateJobResult(job Job) error
InjectJob(Job) error
CreateScheduleJob(ctx context.Context, job ScheduleJob) error
GetScheduledJob(from, to int64) ([]*ScheduleJob, error)
UpdateScheduledJob(ScheduleJob) error
}
type LocalOndemandGovernor ¶
type LocalOndemandGovernor struct {
MaxSleep int
MinSleep int
CurSleep *int
WorkerCounter *int
Locker *sync.Mutex
JobCounter map[string]*int
MaxWorker int
JobDescription map[string]JobDescription
}
func (LocalOndemandGovernor) AddJob ¶
func (g LocalOndemandGovernor) AddJob(title string)
func (LocalOndemandGovernor) DelJob ¶
func (g LocalOndemandGovernor) DelJob(title string)
func (LocalOndemandGovernor) GetCounter ¶
func (g LocalOndemandGovernor) GetCounter() int
func (LocalOndemandGovernor) NoJob ¶
func (g LocalOndemandGovernor) NoJob()
func (LocalOndemandGovernor) Spawn ¶
func (g LocalOndemandGovernor) Spawn() (bool, []string)
type MiddlewareFunc ¶
type MiddlewareFunc func(HandlerFunc) HandlerFunc
type QueueConfig ¶
type QueueConfig struct {
JobDescription map[string]JobDescription `mapstructure:"job_description" yaml:"job_description" json:"job_description"`
CleanError bool `yaml:"clean_error" mapstructure:"clean_error" json:"clean_error"` // will the GC clear maxed try job
Concurrent int `yaml:"concurrent" mapstructure:"concurrent" json:"concurrent"` // number of workers can be run, will ignore JD.Concurrent if it >
BreakTime int `mapstructure:"break_time" yaml:"break_time" json:"break_time"` // miliseconds, break between loop
RampTime int `mapstructure:"ramp_time" yaml:"ramp_time" json:"ramp_time"`
}
type ScheduleJob ¶
type ScheduleJob struct {
ID string `mapstructure:"id" yaml:"id" json:"id"`
JobID string `mapstructure:"job_id" yaml:"job_id" json:"job_id"`
Title string `mapstructure:"title" yaml:"title" json:"title"`
Payload string `mapstructure:"payload" yaml:"payload" json:"payload"`
Priority int `mapstructure:"priority" yaml:"priority" json:"priority"`
Status string `mapstructure:"status" yaml:"status" json:"status"`
UpdatedAt int64 `yaml:"updated_at" mapstructure:"updated_at" json:"updated_at"`
Schedule int64 `json:"schedule"`
ExecuteID string `json:"execute_id"`
Log string `json:"log"`
}
Directories
¶
| Path | Synopsis |
|---|---|
|
store
|
|
|
test
|
|
|
gorm
command
|
|
|
gorm-postgres
command
|
|
|
gorm-sqlite
command
|
|
|
gorvernortest
command
|
|
|
sleepstrike
command
|
|
Click to show internal directories.
Click to hide internal directories.