1 Star 0 Fork 1

iThings/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
timer.go 2.17 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-03-03 23:06 . feat: 对任务管理进行超级升级
package timer
import (
"context"
"gitee.com/i-Things/core/service/timed/internal/domain"
"gitee.com/i-Things/core/service/timed/internal/repo/relationDB"
"gitee.com/i-Things/core/service/timed/timedschedulersvr/internal/svc"
"gitee.com/i-Things/share/ctxs"
"gitee.com/i-Things/share/def"
"gitee.com/i-Things/share/errors"
"gitee.com/i-Things/share/utils"
"time"
)
func Run(svcCtx *svc.ServiceContext) {
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
defer cancel()
//dgsvr 订阅到了设备端数据,此时调用StartSpan方法,将订阅到的主题推送给jaeger
//此时的ctx已经包含当前节点的span信息,会随着 handle(ctx).Publish 传递到下个节点
ctx, span := ctxs.StartSpan(ctx, "timedSchedulersvr.taskRun", "")
defer span.End()
{ //先初始化数据库状态
msg := "初始化数据库执行错误"
jobDB := relationDB.NewTaskInfoRepo(ctx)
//将运行中的任务修改为等待运行
err := jobDB.UpdateByFilter(ctx, &relationDB.TimedTaskInfo{Status: def.StatusWaitRun},
relationDB.TaskFilter{Status: []int64{def.StatusRunning}, Types: []int64{domain.TaskTypeTiming, domain.TaskTypeQueue}})
errors.Must(err, msg)
//将等待暂停的任务调整为已暂停
err = jobDB.UpdateByFilter(ctx, &relationDB.TimedTaskInfo{Status: def.StatusStopped},
relationDB.TaskFilter{Status: []int64{def.StatusWaitStop}, Types: []int64{domain.TaskTypeTiming, domain.TaskTypeQueue}})
errors.Must(err, msg)
//删除等待删除的任务
err = jobDB.DeleteByFilter(ctx, relationDB.TaskFilter{Status: []int64{def.StatusWaitDelete}, Types: []int64{domain.TaskTypeTiming, domain.TaskTypeQueue}})
errors.Must(err, msg)
}
utils.Go(ctx, func() {
ctx := context.Background()
TimingTaskCheck(svcCtx)
utils.Go(ctx, func() {
err := svcCtx.Scheduler.Run()
errors.Must(err, "Scheduler.Run")
})
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
TimingTaskCheck(svcCtx)
}
}
})
utils.Go(ctx, func() {
QueueTaskCheck(svcCtx)
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ticker.C:
QueueTaskCheck(svcCtx)
}
}
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/i-Things/core.git
git@gitee.com:i-Things/core.git
i-Things
core
core
v0.1.6

搜索帮助