chenshijun
2019-09-11 2d152f583afd602d501cc7fb05c54cc244943e70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package tasktag
 
import (
    "sync"
 
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/logger.git"
    "taskpubsub/util"
)
 
var TaskLabelMap sync.Map
 
func Init() {
 
    logger.Info("============= init tasktag info =====================")
    genTaskLabelMap()
    go func(taskflag chan bool) {
        for _ = range taskflag {
            genTaskLabelMap()
            logger.Info("update task finished!")
        }
    }(util.TaskSdkflag)
}
 
// 从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
 
        for _, sdkinfo := range taskSdk.Sdks {
            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)
        newtls = append(newtls, tl)
    }
    updateTaskLabelMap(newtls)
    TaskLabelMap.Range(func(k, v interface{}) bool {
        logger.Info(k, v)
        return true
    })
}
 
func updateTaskLabelMap(taskLabel []protomsg.TaskLabel) {
    TaskLabelMap.Range(func(key interface{}, value interface{}) bool {
        TaskLabelMap.Delete(key)
        return true
    })
 
    for _, value := range taskLabel {
        pv := value
        TaskLabelMap.Store(value.Taskid, &pv)
    }
}