Documentation ¶
Index ¶
Constants ¶
View Source
const (
// the job name that used to register to Jobservice
JobNameScheduler = "SCHEDULER"
)
const definitions
Variables ¶
View Source
var ( // Sched is an instance of the default scheduler that can be used globally Sched = New() )
Functions ¶
func RegisterCallbackFunc ¶
func RegisterCallbackFunc(name string, callbackFunc CallbackFunc) error
RegisterCallbackFunc registers the callback function which will be called when the scheduler is triggered
Types ¶
type CallbackFunc ¶
CallbackFunc defines the function that the scheduler calls when triggered
type DAO ¶
type DAO interface { Create(ctx context.Context, s *schedule) (id int64, err error) List(ctx context.Context, query *q.Query) (schedules []*schedule, err error) Count(ctx context.Context, query *q.Query) (total int64, err error) Get(ctx context.Context, id int64) (s *schedule, err error) Delete(ctx context.Context, id int64) (err error) Update(ctx context.Context, s *schedule, props ...string) (err error) UpdateRevision(ctx context.Context, id, revision int64) (n int64, err error) }
DAO is the data access object interface for schedule
type PeriodicJob ¶
type PeriodicJob struct{}
PeriodicJob is designed to generate hook event periodically
func (*PeriodicJob) MaxCurrency ¶
func (pj *PeriodicJob) MaxCurrency() uint
MaxCurrency is implementation of same method in Interface.
func (*PeriodicJob) Run ¶
func (pj *PeriodicJob) Run(ctx job.Context, _ job.Parameters) error
Run the job
func (*PeriodicJob) ShouldRetry ¶
func (pj *PeriodicJob) ShouldRetry() bool
ShouldRetry indicates job can be retried if failed
func (*PeriodicJob) Validate ¶
func (pj *PeriodicJob) Validate(_ job.Parameters) error
Validate the parameters
type Schedule ¶
type Schedule struct { ID int64 `json:"id"` VendorType string `json:"vendor_type"` VendorID int64 `json:"vendor_id"` CRONType string `json:"cron_type"` CRON string `json:"cron"` ExtraAttrs map[string]interface{} `json:"extra_attrs"` Status string `json:"status"` // status of the underlying task(jobservice job) CreationTime time.Time `json:"creation_time"` UpdateTime time.Time `json:"update_time"` }
Schedule describes the detail information about the created schedule
type Scheduler ¶
type Scheduler interface { // Schedule creates a task which calls the specified callback function periodically // The callback function needs to be registered first // The "vendorType" specifies the type of vendor (e.g. replication, scan, gc, retention, etc.), // and the "vendorID" specifies the ID of vendor if needed(e.g. policy ID for replication and retention). // The "callbackFuncParams" is passed to the callback function as encoded json string, so the callback // function must decode it before using // The customized attributes can be put into the "extraAttrs" Schedule(ctx context.Context, vendorType string, vendorID int64, cronType string, cron string, callbackFuncName string, callbackFuncParams interface{}, extraAttrs map[string]interface{}) (int64, error) // UnScheduleByID the schedule specified by ID UnScheduleByID(ctx context.Context, id int64) error // UnScheduleByVendor the schedule specified by vendor UnScheduleByVendor(ctx context.Context, vendorType string, vendorID int64) error // GetSchedule gets the schedule specified by ID GetSchedule(ctx context.Context, id int64) (*Schedule, error) // ListSchedules according to the query ListSchedules(ctx context.Context, query *q.Query) ([]*Schedule, error) // CountSchedules counts the schedules according to the query CountSchedules(ctx context.Context, query *q.Query) (int64, error) }
Scheduler provides the capability to run a periodic task, a callback function needs to be registered before using the scheduler
Click to show internal directories.
Click to hide internal directories.