Documentation ¶
Index ¶
- Constants
- Variables
- type Job
- func (job *Job) Cancel()
- func (job *Job) GetResult() interface{}
- func (job *Job) IsCancelled() bool
- func (job *Job) IsCancelling() bool
- func (job *Job) IsComplete() bool
- func (job *Job) IsFailed() bool
- func (job *Job) IsFinished() bool
- func (job *Job) IsNotComplete() bool
- func (job *Job) IsPending() bool
- func (job *Job) IsRunning() bool
- func (job *Job) SetResult(result interface{})
- type JobState
- type Runner
- func (s *Runner) AddNamedWorker(name string) (uint64, error)
- func (s *Runner) IsNamedWorkerBusy(worker string) bool
- func (s *Runner) RunCancelableTask(task func(context.Context)) (uint64, error)
- func (s *Runner) RunJob(desc string, task func() error) error
- func (s *Runner) RunJobWithNamedWorker(desc, worker string, task func() error) error
- func (s *Runner) RunJobWithNamedWorkerWithCB(desc, worker string, task func() error, cb func(*Job)) error
- func (s *Runner) RunTask(task func()) error
- func (s *Runner) Stop() error
- func (s *Runner) StopCancelableTask(id uint64) error
Constants ¶
const ( // Pending job is wait to running Pending = JobState(0) // Running job is running Running = JobState(1) // Cancelling job is cancelling Cancelling = JobState(2) // Cancelled job is cancelled Cancelled = JobState(3) // Finished job is complete Finished = JobState(4) // Failed job is failed when execute Failed = JobState(5) )
Variables ¶
var ( // ErrJobCancelled error job cancelled ErrJobCancelled = errors.New("Job cancelled") )
Functions ¶
This section is empty.
Types ¶
type Job ¶
Job is do for something with state
func (*Job) IsCancelled ¶
IsCancelled returns true if job state is Cancelled
func (*Job) IsCancelling ¶
IsCancelling returns true if job state is Cancelling
func (*Job) IsComplete ¶
IsComplete return true means the job is complete.
func (*Job) IsFinished ¶
IsFinished returns true if job state is Finished
func (*Job) IsNotComplete ¶
IsNotComplete return true means the job is not complete.
type Runner ¶
Runner TODO
func (*Runner) AddNamedWorker ¶
AddNamedWorker add a named worker, the named worker has uniq queue, so jobs are linear execution
func (*Runner) IsNamedWorkerBusy ¶
IsNamedWorkerBusy returns true if named queue is not empty
func (*Runner) RunCancelableTask ¶
RunCancelableTask run a task that can be cancelled Example:
err := s.RunCancelableTask(func(ctx context.Context) { select { case <-ctx.Done(): // cancelled case <-time.After(time.Second): // do something } })
if err != nil { // hanle error return }
func (*Runner) RunJobWithNamedWorker ¶
RunJobWithNamedWorker run a job in a named worker
func (*Runner) RunJobWithNamedWorkerWithCB ¶
func (s *Runner) RunJobWithNamedWorkerWithCB(desc, worker string, task func() error, cb func(*Job)) error
RunJobWithNamedWorkerWithCB run a job in a named worker
func (*Runner) Stop ¶
Stop stop all task RunTask will failure with an error Wait complete for the tasks that already in execute Cancel the tasks that is not start
func (*Runner) StopCancelableTask ¶
StopCancelableTask stop cancelable spec task