update task udpate
This commit is contained in:
parent
2f9d40a681
commit
348391cd81
@ -10,5 +10,6 @@ import (
|
||||
|
||||
// mcube
|
||||
func main() {
|
||||
|
||||
cmd.Start()
|
||||
}
|
||||
|
@ -107,4 +107,85 @@ func (i *impl) RunJob(ctx context.Context, in *pipeline.Task) (
|
||||
|
||||
## 任务状态更新
|
||||
|
||||
```go
|
||||
// 更新Job状态
|
||||
func (i *impl) UpdateJobTaskStatus(ctx context.Context, in *task.UpdateJobTaskStatusRequest) (
|
||||
*task.JobTask, error) {
|
||||
ins, err := i.DescribeJobTask(ctx, task.NewDescribeJobTaskRequest(in.Id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 校验更新合法性
|
||||
err = i.CheckAllowUpdate(ctx, ins, in.UpdateToken, in.ForceUpdateStatus)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
i.log.Debug().Msgf("更新任务状态: %s,当前状态: %s, 更新状态: %s",
|
||||
ins.Spec.TaskId, ins.Status.Stage, in.Stage)
|
||||
// 状态更新
|
||||
ins.Status.UpdateStatus(in)
|
||||
|
||||
// 更新数据库
|
||||
if err := i.updateJobTaskStatus(ctx, ins); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Job Task状态变更回调
|
||||
i.JobTaskStatusChangedCallback(ctx, ins)
|
||||
|
||||
// Pipeline Task 状态变更回调
|
||||
if ins.Spec.PipelineTask != "" {
|
||||
// 如果状态未变化, 不触发流水线更新
|
||||
if !in.ForceTriggerPipeline && !ins.Status.Changed {
|
||||
i.log.Debug().Msgf("task %s status not changed: [%s], skip update pipeline", in.Id, in.Stage)
|
||||
return ins, nil
|
||||
}
|
||||
_, err := i.PipelineTaskStatusChanged(ctx, ins)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return ins, nil
|
||||
}
|
||||
|
||||
func (i *impl) JobTaskStatusChangedCallback(ctx context.Context, in *task.JobTask) {
|
||||
// 状态未变化不通知
|
||||
if in.Status == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 状态未变化不通知
|
||||
if !in.Status.Changed {
|
||||
i.log.Debug().Msgf("task %s status not changed [%s], skip status callback", in.Spec.TaskId, in.Status.Stage)
|
||||
return
|
||||
}
|
||||
i.log.Debug().Msgf("task %s 执行状态变化回调...", in.Spec.TaskId)
|
||||
|
||||
// 个人通知
|
||||
for index := range in.Spec.MentionUsers {
|
||||
mu := in.Spec.MentionUsers[index]
|
||||
i.TaskMention(ctx, mu, in)
|
||||
}
|
||||
if len(in.Spec.MentionUsers) > 0 {
|
||||
i.updateJobTaskMentionUser(ctx, in.Spec.TaskId, in.Spec.MentionUsers)
|
||||
}
|
||||
|
||||
// 群组通知
|
||||
imRobotHooks := in.Spec.MatchedImRobotNotify(in.Status.Stage.String())
|
||||
i.log.Debug().Msgf("task %s 群组通知: %v", in.Spec.TaskId, imRobotHooks)
|
||||
i.hook.SendTaskStatus(ctx, imRobotHooks, in)
|
||||
if len(imRobotHooks) > 0 {
|
||||
i.updateJobTaskImRobotNotify(ctx, in.Spec.TaskId, imRobotHooks)
|
||||
}
|
||||
|
||||
// WebHook回调
|
||||
webhooks := in.Spec.MatchedWebHooks(in.Status.Stage.String())
|
||||
i.log.Debug().Msgf("task %s WebHook通知: %v", in.Spec.TaskId, webhooks)
|
||||
i.hook.SendTaskStatus(ctx, webhooks, in)
|
||||
if len(webhooks) > 0 {
|
||||
i.updateJobTaskWebHook(ctx, in.Spec.TaskId, webhooks)
|
||||
}
|
||||
}
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user