Documentation ¶
Index ¶
- Constants
- Variables
- func CurrentServerIP(name string) (string, error)
- func Listen()
- func RunJob(jobId uint64)
- func SetJobDB(db *gorm.DB)
- type BeanstalkdQueue
- type ExtraInput
- type Job
- type QorJob
- func (qj *QorJob) GetJob() *Job
- func (j *QorJob) GetLog() (l string)
- func (j *QorJob) GetLogger() (f *os.File, err error)
- func (qj *QorJob) GetWorker() *Worker
- func (qj *QorJob) LogPath() string
- func (j *QorJob) Run() (err error)
- func (j *QorJob) SaveRunStatus() (err error)
- func (q *QorJob) URL() string
- func (j *QorJob) UpdateStatus(status string) (err error)
- type Queuer
- type Worker
Constants ¶
View Source
const ( // Job statuses StatusToRun = "Pending" StatusRunning = "Running" StatusFailed = "Failed" StatusKilled = "Killed" StatusDone = "Done" )
Variables ¶
View Source
var ( WorkerDataPath = "worker_data" DefaultServerHost = func() string { ip, err := CurrentServerIP("") if err != nil { fmt.Println("failed to retrieve current host ip") } return ip }() DefaultServerUser = "app" DefaultServerSSHPort = "22" )
View Source
var (
DefaultJobCli = strings.Join(os.Args, " ")
)
View Source
var ErrJobDone = errors.New("job is finished")
Functions ¶
func CurrentServerIP ¶
Types ¶
type BeanstalkdQueue ¶
func NewBeanstalkdQueue ¶
func NewBeanstalkdQueue(name, addr string) (bq *BeanstalkdQueue)
func (*BeanstalkdQueue) Dequeue ¶
func (bq *BeanstalkdQueue) Dequeue() (jobId uint64, err error)
func (*BeanstalkdQueue) Enqueue ¶
func (bq *BeanstalkdQueue) Enqueue(job *QorJob) (err error)
func (*BeanstalkdQueue) Name ¶
func (bq *BeanstalkdQueue) Name() string
func (*BeanstalkdQueue) Purge ¶
func (bq *BeanstalkdQueue) Purge(job *QorJob) (err error)
type ExtraInput ¶
func (*ExtraInput) Scan ¶
func (ei *ExtraInput) Scan(src interface{}) error
type Job ¶
type Job struct { Name string Queuer Queuer Description string Resource *admin.Resource Handle func(job *QorJob) error OnKill func(job *QorJob) error OnStart func(job *QorJob) error OnSuccess func(job *QorJob) OnFailed func(job *QorJob) // contains filtered or unexported fields }
type QorJob ¶
type QorJob struct { ID uint64 QueueJobId string // unit: minute // 0 to run job only once Interval uint64 // zero time value to execute job immediately StartAt time.Time Stopped bool Cli string WorkerName string JobName string Status string PID int // TODO: change it into uint By string RunCounter uint64 FailCounter uint64 SuccessCounter uint64 KillCounter uint64 ServerHost string ServerUser string ServerSSHPort string ExtraValue *ExtraInput `sql:"type:text;"` // Mysql: 64KB ExtraFile *ExtraInput `sql:"type:text;"` // Mysql: 64KB UpdatedAt time.Time CreatedAt time.Time DeletedAt time.Time Progress int // contains filtered or unexported fields }
func (*QorJob) SaveRunStatus ¶
TODO: dequeue job will override value?
func (*QorJob) UpdateStatus ¶
type Queuer ¶
type Queuer interface { // Name returns the Queuer's identifier Name() string // Enqueue pushes a job to a queue, also a Queuer could set a id value (string) // in QorJob's QueueJobId if needed // Interval // StartAt Enqueue(job *QorJob) (err error) // Purge removes a job from a queue Purge(job *QorJob) (err error) // Dequeue blocks the process until a job id (and error if any) is returned Dequeue() (jobId uint64, err error) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.