zhangqian
2023-10-08 d4243f398b84a8b8cdcd27c35ace72f6a30a6452
是否可以开始增加开始时间判断,考虑进程退出和断电情况
4个文件已修改
26 ■■■■ 已修改文件
api/v1/task.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/procedures.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/cache_store.go 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/task.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/task.go
@@ -111,8 +111,9 @@
        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
        }
    }
model/procedures.go
@@ -140,6 +140,11 @@
    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{})
service/cache_store.go
@@ -5,6 +5,7 @@
    "apsClient/model"
    "fmt"
    "github.com/spf13/cast"
    "gorm.io/gorm"
    "sync"
    "time"
)
@@ -79,18 +80,25 @@
}
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) {
service/task.go
@@ -49,7 +49,7 @@
            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 {