package service import ( "context" ) // CronService 定义了定时任务相关的业务接口 type CronService interface { // StartAllJobs 启动所有定时任务 StartAllJobs(ctx context.Context) error // StopAllJobs 停止所有定时任务 StopAllJobs(ctx context.Context) error // AddJob 添加定时任务 AddJob(ctx context.Context, name, cron string, job func()) error // RemoveJob 移除定时任务 RemoveJob(ctx context.Context, name string) error // GetJobStatus 获取任务状态 GetJobStatus(ctx context.Context, name string) (bool, error) } var cronService CronService // Cron 返回 CronService 的实例 func Cron() CronService { if cronService == nil { panic("implement not found for interface CronService") } return cronService } // SetCron 注册 CronService 实现 func SetCron(s CronService) { cronService = s }