Versions in this module Expand all Collapse all v0 v0.4.1 May 19, 2021 Changes in this version + var ErrOption = errors.New("option invalid") v0.4.0 May 17, 2021 Changes in this version + var ErrConfigEmptyTable = errors.New("config table is empty") + var ErrConfigInvalidInitializeTimeout = errors.New("config initialize timeout is invalid") + var ErrConfigInvalidInstantScanInterval = errors.New("config instant scan interval is invalid") + var ErrConfigInvalidRunningTimeout = errors.New("config running timeout is invalid") + var ErrConfigInvalidScanInterval = errors.New("config scan interval is invalid") + var ErrConfigNilDB = errors.New("config db is nil") + var ErrDefEmptyPrimaryKey = errors.New("definition primary key is empty") + var ErrDefInvalidArgument = errors.New("definition argument is invalid") + var ErrDefInvalidLoopInterval = errors.New("definition loop interval is invalid") + var ErrDefNilHandler = errors.New("definition handler is nil") + var ErrTaskNotFound = errors.New("task not found") + var ErrUnexpected = errors.New("unexpected") + var ErrZeroRowsAffected = errors.New("zero rows affected") + func Register(key TaskKey, definition TaskDefinition) + func Run(ctx context.Context, key TaskKey, arg interface{}) error + func RunWithTx(tx *gorm.DB, ctx context.Context, key TaskKey, arg interface{}) error + func StartWithOptions(db *gorm.DB, table string, options ...Option) + func Stop(wait bool) + func Transaction(fc func(tx *gorm.DB) error) (err error) + type CtxMarshaler interface + MarshalCtx func(ctx context.Context) ([]byte, error) + UnmarshalCtx func(bytes []byte) (context.Context, error) + type Logger interface + Errorf func(format string, args ...interface{}) + Infof func(format string, args ...interface{}) + Printf func(format string, args ...interface{}) + Warnf func(format string, args ...interface{}) + type Option func(c *TaskConfig) + func WithCheckCallback(f func(logger Logger, abnormalTasks []Task)) Option + func WithConfig(config TaskConfig) Option + func WithContext(ctx context.Context) Option + func WithCtxMarshaler(m CtxMarshaler) Option + func WithDryRun(flag bool) Option + func WithInitializedTimeout(d time.Duration) Option + func WithInstantScanInterval(d time.Duration) Option + func WithLoggerFactory(f func(ctx context.Context) Logger) Option + func WithPoolSize(size int) Option + func WithRunningTimeout(d time.Duration) Option + func WithScanInterval(d time.Duration) Option + func WithStorageTimeout(d time.Duration) Option + func WithWaitTimeout(d time.Duration) Option + type Task struct + Argument []byte + Context []byte + CreatedAt time.Time + Extra TaskExtra + ID uint64 + TaskKey TaskKey + TaskStatus TaskStatus + UpdatedAt time.Time + type TaskConfig struct + CheckCallback func(logger Logger, abnormalTasks []Task) + Context context.Context + CtxMarshaler CtxMarshaler + DB *gorm.DB + DryRun bool + InitializedTimeout time.Duration + InstantScanInterval time.Duration + LoggerFactory func(ctx context.Context) Logger + PoolSize int + RunningTimeout time.Duration + ScanInterval time.Duration + StorageTimeout time.Duration + Table string + WaitTimeout time.Duration + type TaskDefinition struct + ArgType reflect.Type + CleanSucceeded bool + CtxMarshaler CtxMarshaler + Handler TaskHandler + InitTimeoutSensitive bool + RetryInterval func(times int) time.Duration + RetryTimes int + type TaskExtra struct + func (s *TaskExtra) Scan(v interface{}) error + func (s TaskExtra) Value() (driver.Value, error) + type TaskHandler func(ctx context.Context, arg interface{}) (err error) + type TaskKey string + type TaskManager struct + func DefaultManager() *TaskManager + func NewTaskManager(db *gorm.DB, table string, options ...Option) *TaskManager + func (s *TaskManager) ForceRerunTasks(taskIDs []uint64, status TaskStatus) (int64, error) + func (s *TaskManager) QueryUnsuccessfulTasks(limit, offset int) ([]Task, error) + func (s *TaskManager) Register(key TaskKey, definition TaskDefinition) + func (s *TaskManager) Run(ctx context.Context, key TaskKey, arg interface{}) error + func (s *TaskManager) RunWithTx(tx *gorm.DB, ctx context.Context, key TaskKey, arg interface{}) error + func (s *TaskManager) Start() + func (s *TaskManager) Stop(wait bool) + func (s *TaskManager) Transaction(fc func(tx *gorm.DB) error) (err error) + type TaskStatus string + const TaskStatusFailed + const TaskStatusInitialized + const TaskStatusRunning + const TaskStatusSucceeded + const TaskStatusUnKnown