是否可以开始增加开始时间判断,考虑进程退出和断电情况
| | |
| | | return taskResponse.Tasks[i].Channel < taskResponse.Tasks[i].Channel |
| | | }) |
| | | |
| | | nowTs := time.Now().Unix() |
| | | for _, task := range taskResponse.Tasks { |
| | | if !service.TaskFlagGet(task.Channel) { |
| | | if !service.TaskFlagGet(task.Channel) && task.Procedure.StartTime <= nowTs { |
| | | task.CanStarted = true |
| | | } |
| | | } |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) SetChannel(channel int32) *ProceduresSearch { |
| | | slf.Channel = channel |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProceduresSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Procedures{}) |
| | | |
| | |
| | | "apsClient/model" |
| | | "fmt" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "sync" |
| | | "time" |
| | | ) |
| | |
| | | } |
| | | |
| | | func TaskFlagSet(channel int32) { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), struct{}{}) |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), true) |
| | | } |
| | | |
| | | func TaskFlagUnset(channel int32) { |
| | | defaultCacheStore.Remove(fmt.Sprintf(CurrentTaskCacheKey, channel)) |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), false) |
| | | } |
| | | |
| | | func TaskFlagGet(channel int32) bool { |
| | | if _, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentTaskCacheKey, channel)); ok { |
| | | if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentTaskCacheKey, channel)); ok { |
| | | return v.(bool) |
| | | } |
| | | _, err := model.NewProceduresSearch(nil).SetStatus(model.ProcedureStatusProcessing).SetChannel(channel).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), false) |
| | | return false |
| | | } else { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentTaskCacheKey, channel), true) |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func ProgressCacheGet(channel int32) (*model.ProductionProgress, bool) { |
| | |
| | | SetOrder("start_time asc") |
| | | } else if mode == constvar.TaskModeCurrent { |
| | | search.SetStatus(model.ProcedureStatusProcessing). |
| | | SetOrder("status desc, start_time asc") |
| | | SetOrder("start_time asc") |
| | | } else if mode == constvar.TaskModeLastFinished { |
| | | search.SetStatus(model.ProcedureStatusFinished).SetOrder("updated_at desc") |
| | | if len(channels) > 0 { |