main.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package main
  2. import (
  3. "qfw/util"
  4. "qfw/util/mongodb"
  5. "qfw/util/redis"
  6. "sync"
  7. "time"
  8. "gopkg.in/mgo.v2/bson"
  9. )
  10. const (
  11. REDISIDS = "ids"
  12. REDISKEYS = "keys"
  13. INFOID = "info"
  14. INFOTIMEOUT = 86400 * 30
  15. )
  16. var (
  17. Sysconfig map[string]interface{}
  18. MQFW mongodb.MongodbSim
  19. extractColl, projectColl string
  20. lenprojectname int
  21. MultiThread chan bool
  22. IdLock = &sync.Mutex{}
  23. PncbMayLock = &sync.Mutex{}
  24. MegerFieldsLen *MegerFields
  25. //三组lock,对应的(PNKey)key为项目名称,值对应的是此项目名称对应的项目id数组
  26. PNKey, PCKey, PBKey = NewKeyMap(), NewKeyMap(), NewKeyMap()
  27. PNKeyMap, PCKeyMap, PBKeyMap = sync.Map{}, sync.Map{}, sync.Map{}
  28. currentMegerTime int64 //合并项目的时间位置,用来清理几个月之前的项目
  29. currentMegerCount int //合并项目的计数,用来定时清理
  30. )
  31. type MegerFields struct {
  32. ProjectNamelen int
  33. ProjectCodelen int
  34. }
  35. type KeyMap struct {
  36. Lock sync.Mutex
  37. Map map[string]*Key
  38. }
  39. type Key struct {
  40. Arr *[]string
  41. Lock *sync.Mutex
  42. }
  43. func NewKeyMap() *KeyMap {
  44. return &KeyMap{
  45. Map: map[string]*Key{},
  46. }
  47. }
  48. func init() {
  49. initarea()
  50. util.ReadConfig(&Sysconfig)
  51. MultiThread = make(chan bool, util.IntAllDef(Sysconfig["thread"], 200))
  52. lenprojectname = util.IntAllDef(Sysconfig["lenprojectname"], 20) - 1
  53. megerfields, _ := Sysconfig["megerfields"].(map[string]interface{})
  54. MegerFieldsLen = &MegerFields{
  55. ProjectNamelen: util.IntAllDef(megerfields["projectlen"], 5),
  56. ProjectCodelen: util.IntAllDef(megerfields["projectcodelen"], 8),
  57. }
  58. redis.InitRedisBySize(Sysconfig["redisaddrs"].(string), util.IntAllDef(Sysconfig["redisPoolSize"], 100), 30, 300)
  59. MQFW = mongodb.MongodbSim{
  60. MongodbAddr: Sysconfig["mongodbServers"].(string),
  61. Size: util.IntAll(Sysconfig["mongodbPoolSize"]),
  62. DbName: Sysconfig["mongodbName"].(string),
  63. }
  64. MQFW.InitPool()
  65. extractColl = Sysconfig["extractColl"].(string)
  66. projectColl = Sysconfig["projectColl"].(string)
  67. }
  68. func main() {
  69. RunFullData()
  70. time.Sleep(99999 * time.Hour)
  71. }
  72. func NewPushInfo(tmp map[string]interface{}) bson.M {
  73. return bson.M{
  74. "comeintime": tmp["comeintime"],
  75. "publishtime": tmp["publishtime"],
  76. "title": tmp["title"],
  77. "toptype": tmp["toptype"],
  78. "subtype": tmp["subtype"],
  79. "infoformat": tmp["infoformat"],
  80. "infoid": util.BsonIdToSId(tmp["_id"]),
  81. "href": tmp["href"],
  82. "area": tmp["area"],
  83. "city": tmp["city"],
  84. "cresult": tmp["cresult"],
  85. "score": tmp["score"],
  86. }
  87. }