chenshijun
2019-09-11 9389544d4cc56ef00084e8dbb6afb73e1ec00eca
tasktag/tasktag.go
@@ -4,60 +4,60 @@
   "sync"
   "basic.com/pubsub/protomsg.git"
   "github.com/long/taskpubsub/util"
    "github.com/long/taskpubsub/logger"
   "taskpubsub/logger"
   "taskpubsub/util"
)
var TaskMapLab sync.Map
var TaskLabelMap sync.Map
func Init() {
   logger.Info("============= init tasktag info =====================")
   GenTaskMap()
   genTaskLabelMap()
   go func(taskflag chan bool) {
      for _ = range taskflag {
         GenTaskMap()
         genTaskLabelMap()
         logger.Info("update task finished!")
      }
   }(util.TaskSdkflag)
}
func GenTaskMap() {
   var tls []protomsg.TaskLabel
// 从sqlite 接口拿到所有的任务, 每一个任务都有自己的几个算法
//以 taskid 作为key, 对应的算法组合作为 value
func genTaskLabelMap() {
   var newtls []protomsg.TaskLabel
   for _, taskSdk := range util.TaskSdks {
      var tl protomsg.TaskLabel
      tl.Taskid = taskSdk.Task.Taskid
        tl.Taskname = taskSdk.Task.Taskname
      tl.Taskname = taskSdk.Task.Taskname
      for _, sdkinfo := range taskSdk.Sdks {
            sdkinfowithtask := new(protomsg.SdkmsgWithTask)
            sdkinfowithtask.Ipcid = sdkinfo.IpcId
            sdkinfowithtask.Sdktype = sdkinfo.SdkType
            sdkinfowithtask.Sdkdata = make([]byte, 1)
            tl.Sdkinfos = append(tl.Sdkinfos, sdkinfowithtask)
         sdkinfowithtask := new(protomsg.SdkmsgWithTask)
         sdkinfowithtask.Ipcid = sdkinfo.IpcId
         sdkinfowithtask.Sdktype = sdkinfo.SdkType
         logger.Info("======sdkinfowithtask.Sdktype:", sdkinfowithtask.Sdktype)
         sdkinfowithtask.Sdkdata = make([]byte, 1)
         tl.Sdkinfos = append(tl.Sdkinfos, sdkinfowithtask)
      }
      tl.Index = int32(0)
      tls = append(tls, tl)
      newtls = append(newtls, tl)
   }
   GenTasklab(tls)
   TaskMapLab.Range(func(k, v interface{}) bool {
   updateTaskLabelMap(newtls)
   TaskLabelMap.Range(func(k, v interface{}) bool {
      logger.Info(k, v)
      return true
   })
}
// 从sqlite 接口拿到所有的任务, 每一个任务都有自己的几个算法
//以 taskid 作为key, 对应的算法组合作为 value
func GenTasklab(tasklab []protomsg.TaskLabel) {
   TaskMapLab.Range(func(key interface{}, value interface{}) bool {
      TaskMapLab.Delete(key)
func updateTaskLabelMap(taskLabel []protomsg.TaskLabel) {
   TaskLabelMap.Range(func(key interface{}, value interface{}) bool {
      TaskLabelMap.Delete(key)
      return true
   })
   for _, value := range tasklab {
   for _, value := range taskLabel {
      pv := value
      TaskMapLab.Store(value.Taskid, &pv)
      TaskLabelMap.Store(value.Taskid, &pv)
   }
}