Documentation
¶
Index ¶
- type CronJob
- type CronJobState
- type CronPayload
- type CronSchedule
- type CronService
- func (cs *CronService) AddJob(name string, schedule CronSchedule, message string, userID string) (*CronJob, error)
- func (cs *CronService) EnableJob(jobID string, enabled bool) *CronJob
- func (cs *CronService) ListJobs(includeDisabled bool) []CronJob
- func (cs *CronService) RemoveJob(jobID string) bool
- func (cs *CronService) SetMaxJobs(max int)
- func (cs *CronService) SetMaxJobsPerUser(max int)
- func (cs *CronService) SetOnJob(handler JobHandler)
- func (cs *CronService) Start() error
- func (cs *CronService) Status() map[string]any
- func (cs *CronService) Stop()
- type FileStore
- type GormStore
- type JobHandler
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CronJob ¶
type CronJob struct {
ID string `json:"id" gorm:"column:id;primaryKey;type:varchar(32)"`
UserID string `json:"userId,omitempty" gorm:"column:user_id;type:varchar(64);index"`
Name string `json:"name" gorm:"column:name;type:varchar(100)"`
Enabled bool `json:"enabled" gorm:"column:enabled"`
Schedule CronSchedule `json:"schedule" gorm:"embedded"`
Payload CronPayload `json:"payload" gorm:"embedded"`
State CronJobState `json:"state" gorm:"embedded"`
CreatedAtMS int64 `json:"createdAtMs" gorm:"column:created_at_ms"`
UpdatedAtMS int64 `json:"updatedAtMs" gorm:"column:updated_at_ms"`
DeleteAfterRun bool `json:"deleteAfterRun" gorm:"column:delete_after_run"`
}
CronJob 表示一个定时任务
type CronJobState ¶
type CronJobState struct {
NextRunAtMS *int64 `json:"nextRunAtMs,omitempty" gorm:"column:next_run_at_ms"`
LastRunAtMS *int64 `json:"lastRunAtMs,omitempty" gorm:"column:last_run_at_ms"`
LastStatus string `json:"lastStatus,omitempty" gorm:"column:last_status;type:varchar(20)"`
LastError string `json:"lastError,omitempty" gorm:"column:last_error;type:text"`
}
CronJobState 定义任务的运行状态
type CronPayload ¶
type CronPayload struct {
Message string `json:"message" gorm:"column:message;type:text"`
}
CronPayload 定义任务触发时携带的信息
type CronSchedule ¶
type CronSchedule struct {
Kind string `json:"kind" gorm:"column:kind;type:varchar(10);not null"` // "at" | "every" | "cron"
AtMS *int64 `json:"atMs,omitempty" gorm:"column:at_ms"` // Kind=at 时的触发时间戳(毫秒)
EveryMS *int64 `json:"everyMs,omitempty" gorm:"column:every_ms"` // Kind=every 时的间隔(毫秒)
Expr string `json:"expr,omitempty" gorm:"column:expr;type:varchar(100)"` // Kind=cron 时的 cron 表达式
}
CronSchedule 定义任务的调度方式
type CronService ¶
type CronService struct {
// contains filtered or unexported fields
}
CronService 定时调度服务
func NewCronService ¶
func NewCronService(store Store, onJob JobHandler) *CronService
NewCronService 创建定时调度服务
func (*CronService) AddJob ¶
func (cs *CronService) AddJob(name string, schedule CronSchedule, message string, userID string) (*CronJob, error)
AddJob 添加定时任务
func (*CronService) EnableJob ¶
func (cs *CronService) EnableJob(jobID string, enabled bool) *CronJob
EnableJob 启用/禁用任务
func (*CronService) ListJobs ¶
func (cs *CronService) ListJobs(includeDisabled bool) []CronJob
ListJobs 列出任务
func (*CronService) SetMaxJobs ¶
func (cs *CronService) SetMaxJobs(max int)
SetMaxJobs 设置最大任务数量限制,0 表示不限制
func (*CronService) SetMaxJobsPerUser ¶
func (cs *CronService) SetMaxJobsPerUser(max int)
SetMaxJobsPerUser 设置单用户最大任务数量限制,0 表示不限制
func (*CronService) SetOnJob ¶
func (cs *CronService) SetOnJob(handler JobHandler)
SetOnJob 设置任务触发回调
type GormStore ¶
type GormStore struct {
// contains filtered or unexported fields
}
GormStore 基于 GORM 的数据库存储实现 支持 MySQL、PostgreSQL、SQLite
Click to show internal directories.
Click to hide internal directories.