Skip to content

Commit

Permalink
feature(1.2.7): 新增 cron_server - 后台任务
Browse files Browse the repository at this point in the history
- 优化代码;
  • Loading branch information
xinliangnote committed Sep 5, 2021
1 parent f17f6a7 commit f47f57e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion internal/cron/cron_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ type server struct {

type Server interface {
i()

// Start 启动 cron 服务
Start()

// Stop 停止 cron 服务
Stop()

// AddTask 增加定时任务
AddTask(task *cron_task_repo.CronTask)
AddJob(task *cron_task_repo.CronTask) cron.FuncJob

// RemoveTask 删除定时任务
RemoveTask(taskId int)

// AddJob 增加定时任务执行的工作内容
AddJob(task *cron_task_repo.CronTask) cron.FuncJob
}

func New(logger *zap.Logger, db db.Repo, cache cache.Repo) (Server, error) {
Expand Down
5 changes: 4 additions & 1 deletion internal/cron/cron_server/service_add_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ func (s *server) AddJob(task *cron_task_repo.CronTask) cron.FuncJob {
s.taskCount.Add()
defer s.taskCount.Done()

msg := fmt.Sprintf("开始执行任务:(%d)%s [%s]", task.Id, task.Name, task.Spec)
// 将 task 信息写入到 Kafka Topic 中,任务执行器订阅 Topic 如果为符合条件的任务并进行执行,反之不执行
// 为了便于演示,不写入到 Kafka 中,仅记录日志

msg := fmt.Sprintf("执行任务:(%d)%s [%s]", task.Id, task.Name, task.Spec)
s.logger.Info(msg)
}
}

0 comments on commit f47f57e

Please sign in to comment.