|
@@ -8,6 +8,7 @@ import (
|
|
mu "mfw/util"
|
|
mu "mfw/util"
|
|
"net"
|
|
"net"
|
|
"os"
|
|
"os"
|
|
|
|
+ qu "qfw/common/src/qfw/util"
|
|
"qfw/util"
|
|
"qfw/util"
|
|
"strconv"
|
|
"strconv"
|
|
"sync"
|
|
"sync"
|
|
@@ -18,64 +19,61 @@ import (
|
|
func historyRepeat() {
|
|
func historyRepeat() {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
for {
|
|
for {
|
|
- start:=time.Now().Unix()
|
|
|
|
- if gtid=="" {
|
|
|
|
|
|
+ start := time.Now().Unix()
|
|
|
|
+ if gtid == "" {
|
|
log.Println("请传gtid,否则无法运行")
|
|
log.Println("请传gtid,否则无法运行")
|
|
os.Exit(0)
|
|
os.Exit(0)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if lteid!="" {
|
|
|
|
- //先进行数据迁移
|
|
|
|
- log.Println("开启一次迁移任务",gtid,lteid)
|
|
|
|
- moveHistoryData(gtid,lteid)
|
|
|
|
|
|
+ if lteid != "" && !IsFull { //先进行数据迁移
|
|
|
|
+ log.Println("开启一次迁移任务", gtid, lteid)
|
|
|
|
+ moveHistoryData(gtid, lteid)
|
|
gtid = lteid //替换数据
|
|
gtid = lteid //替换数据
|
|
}
|
|
}
|
|
//查询表最后一个id
|
|
//查询表最后一个id
|
|
task_sess := task_mgo.GetMgoConn()
|
|
task_sess := task_mgo.GetMgoConn()
|
|
defer task_mgo.DestoryMongoConn(task_sess)
|
|
defer task_mgo.DestoryMongoConn(task_sess)
|
|
- q:=map[string]interface{}{}
|
|
|
|
- between_time := time.Now().Unix() - (86400 * timingPubScope)//两年周期
|
|
|
|
|
|
+ q := map[string]interface{}{}
|
|
it_last := task_sess.DB(task_mgo.DbName).C(task_collName).Find(&q).Sort("-_id").Iter()
|
|
it_last := task_sess.DB(task_mgo.DbName).C(task_collName).Find(&q).Sort("-_id").Iter()
|
|
-
|
|
|
|
- isRepeatStatus:=false
|
|
|
|
|
|
+ isRepeatStatus := false
|
|
for tmp := make(map[string]interface{}); it_last.Next(&tmp); {
|
|
for tmp := make(map[string]interface{}); it_last.Next(&tmp); {
|
|
- is_repeat_status:=util.IntAll(tmp["is_repeat_status"])
|
|
|
|
|
|
+ is_repeat_status := util.IntAll(tmp["is_repeat_status"])
|
|
if is_repeat_status == 1 {
|
|
if is_repeat_status == 1 {
|
|
lteid = util.ObjToString(tmp["lteid"])
|
|
lteid = util.ObjToString(tmp["lteid"])
|
|
- log.Println("查询的最后一个已标记的任务lteid:",lteid)
|
|
|
|
|
|
+ log.Println("查询的最后一个已标记的任务lteid:", lteid)
|
|
isRepeatStatus = true
|
|
isRepeatStatus = true
|
|
tmp = make(map[string]interface{})
|
|
tmp = make(map[string]interface{})
|
|
break
|
|
break
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
tmp = make(map[string]interface{})
|
|
tmp = make(map[string]interface{})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
if !isRepeatStatus {
|
|
if !isRepeatStatus {
|
|
log.Println("查询不到有标记的lteid数据")
|
|
log.Println("查询不到有标记的lteid数据")
|
|
- log.Println("睡眠5分钟 gtid:",gtid,"lteid:",lteid)
|
|
|
|
|
|
+ log.Println("睡眠5分钟 gtid:", gtid, "lteid:", lteid)
|
|
time.Sleep(5 * time.Minute)
|
|
time.Sleep(5 * time.Minute)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- log.Println("查询完毕-找到有标记的lteid-先睡眠5分钟",gtid,lteid)
|
|
|
|
- if isUpdateSite{
|
|
|
|
|
|
+ log.Println("查询完毕-找到有标记的lteid-先睡眠5分钟", gtid, lteid)
|
|
|
|
+ if isUpdateSite {
|
|
initSite()
|
|
initSite()
|
|
}
|
|
}
|
|
time.Sleep(5 * time.Minute)
|
|
time.Sleep(5 * time.Minute)
|
|
|
|
|
|
- sess := data_mgo.GetMgoConn()//连接器
|
|
|
|
|
|
+ sess := data_mgo.GetMgoConn() //连接器
|
|
defer data_mgo.DestoryMongoConn(sess)
|
|
defer data_mgo.DestoryMongoConn(sess)
|
|
|
|
+ between_time := time.Now().Unix() - (86400 * timingPubScope) //两年周期
|
|
//开始判重
|
|
//开始判重
|
|
q = map[string]interface{}{
|
|
q = map[string]interface{}{
|
|
"_id": map[string]interface{}{
|
|
"_id": map[string]interface{}{
|
|
- "$gt": StringTOBsonId(gtid),
|
|
|
|
|
|
+ "$gt": StringTOBsonId(gtid),
|
|
"$lte": StringTOBsonId(lteid),
|
|
"$lte": StringTOBsonId(lteid),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
- log.Println("历史判重查询条件:",q,"时间:", between_time)
|
|
|
|
|
|
+ log.Println("历史判重查询条件:", q, "时间:", between_time)
|
|
it := sess.DB(data_mgo.DbName).C(extract).Find(&q).Sort("publishtime").Iter()
|
|
it := sess.DB(data_mgo.DbName).C(extract).Find(&q).Sort("publishtime").Iter()
|
|
- num,oknum,outnum, deterTime:= int64(0),int64(0),int64(0),int64(0) //计数
|
|
|
|
- pendAllArr:=[][]map[string]interface{}{}//待处理数组
|
|
|
|
|
|
+ num, oknum, outnum, deterTime := int64(0), int64(0), int64(0), int64(0) //计数
|
|
|
|
+ pendAllArr := [][]map[string]interface{}{} //待处理数组
|
|
dayArr := []map[string]interface{}{}
|
|
dayArr := []map[string]interface{}{}
|
|
for tmp := make(map[string]interface{}); it.Next(&tmp); num++ {
|
|
for tmp := make(map[string]interface{}); it.Next(&tmp); num++ {
|
|
if num%10000 == 0 {
|
|
if num%10000 == 0 {
|
|
@@ -86,32 +84,32 @@ func historyRepeat() {
|
|
pubtime := util.Int64All(tmp["publishtime"])
|
|
pubtime := util.Int64All(tmp["publishtime"])
|
|
if pubtime > 0 && pubtime >= between_time {
|
|
if pubtime > 0 && pubtime >= between_time {
|
|
oknum++
|
|
oknum++
|
|
- if deterTime==0 {
|
|
|
|
|
|
+ if deterTime == 0 {
|
|
log.Println("找到第一条符合条件的数据")
|
|
log.Println("找到第一条符合条件的数据")
|
|
deterTime = util.Int64All(tmp["publishtime"])
|
|
deterTime = util.Int64All(tmp["publishtime"])
|
|
- dayArr = append(dayArr,tmp)
|
|
|
|
- }else {
|
|
|
|
- if pubtime-deterTime >timingSpanDay*86400 {
|
|
|
|
|
|
+ dayArr = append(dayArr, tmp)
|
|
|
|
+ } else {
|
|
|
|
+ if pubtime-deterTime > timingSpanDay*86400 {
|
|
//新数组重新构建,当前组数据加到全部组数据
|
|
//新数组重新构建,当前组数据加到全部组数据
|
|
- pendAllArr = append(pendAllArr,dayArr)
|
|
|
|
|
|
+ pendAllArr = append(pendAllArr, dayArr)
|
|
dayArr = []map[string]interface{}{}
|
|
dayArr = []map[string]interface{}{}
|
|
deterTime = util.Int64All(tmp["publishtime"])
|
|
deterTime = util.Int64All(tmp["publishtime"])
|
|
- dayArr = append(dayArr,tmp)
|
|
|
|
- }else {
|
|
|
|
- dayArr = append(dayArr,tmp)
|
|
|
|
|
|
+ dayArr = append(dayArr, tmp)
|
|
|
|
+ } else {
|
|
|
|
+ dayArr = append(dayArr, tmp)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
outnum++
|
|
outnum++
|
|
//不在两年内的也清标记
|
|
//不在两年内的也清标记
|
|
- Update.updatePool <- []map[string]interface{}{//重复数据打标签
|
|
|
|
|
|
+ Update.updatePool <- []map[string]interface{}{ //重复数据打标签
|
|
map[string]interface{}{
|
|
map[string]interface{}{
|
|
"_id": tmp["_id"],
|
|
"_id": tmp["_id"],
|
|
},
|
|
},
|
|
map[string]interface{}{
|
|
map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
- "dataging": 0,
|
|
|
|
- "history_updatetime":util.Int64All(time.Now().Unix()),
|
|
|
|
|
|
+ "dataging": 0,
|
|
|
|
+ "history_updatetime": util.Int64All(time.Now().Unix()),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
@@ -120,30 +118,30 @@ func historyRepeat() {
|
|
tmp = make(map[string]interface{})
|
|
tmp = make(map[string]interface{})
|
|
}
|
|
}
|
|
|
|
|
|
- if len(dayArr)>0 {
|
|
|
|
- pendAllArr = append(pendAllArr,dayArr)
|
|
|
|
|
|
+ if len(dayArr) > 0 {
|
|
|
|
+ pendAllArr = append(pendAllArr, dayArr)
|
|
dayArr = []map[string]interface{}{}
|
|
dayArr = []map[string]interface{}{}
|
|
}
|
|
}
|
|
|
|
|
|
- log.Println("查询数量:",num,"符合条件:",oknum,"未在两年内:",outnum)
|
|
|
|
|
|
+ log.Println("查询数量:", num, "符合条件:", oknum, "未在两年内:", outnum)
|
|
|
|
|
|
if len(pendAllArr) <= 0 {
|
|
if len(pendAllArr) <= 0 {
|
|
log.Println("没找到dataging==1的数据")
|
|
log.Println("没找到dataging==1的数据")
|
|
}
|
|
}
|
|
|
|
|
|
//测试分组数量是否正确
|
|
//测试分组数量是否正确
|
|
- testNum:=0
|
|
|
|
- for k,v:=range pendAllArr {
|
|
|
|
- log.Println("第",k,"组--","数量:",len(v))
|
|
|
|
- testNum = testNum+len(v)
|
|
|
|
|
|
+ testNum := 0
|
|
|
|
+ for k, v := range pendAllArr {
|
|
|
|
+ log.Println("第", k, "组--", "数量:", len(v))
|
|
|
|
+ testNum = testNum + len(v)
|
|
}
|
|
}
|
|
- log.Println("本地构建分组完成:",len(pendAllArr),"组","测试-总计数量:",testNum)
|
|
|
|
|
|
+ log.Println("本地构建分组完成:", len(pendAllArr), "组", "测试-总计数量:", testNum)
|
|
|
|
|
|
n, repeateN := 0, 0
|
|
n, repeateN := 0, 0
|
|
- log.Println("线程数:",threadNum)
|
|
|
|
|
|
+ log.Println("线程数:", threadNum)
|
|
pool := make(chan bool, threadNum)
|
|
pool := make(chan bool, threadNum)
|
|
wg := &sync.WaitGroup{}
|
|
wg := &sync.WaitGroup{}
|
|
- for k,v:=range pendAllArr { //每组结束更新一波数据
|
|
|
|
|
|
+ for k, v := range pendAllArr { //每组结束更新一波数据
|
|
pool <- true
|
|
pool <- true
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
go func(k int, v []map[string]interface{}) {
|
|
go func(k int, v []map[string]interface{}) {
|
|
@@ -151,10 +149,6 @@ func historyRepeat() {
|
|
<-pool
|
|
<-pool
|
|
wg.Done()
|
|
wg.Done()
|
|
}()
|
|
}()
|
|
- //相关ids 跨表
|
|
|
|
- groupOtherExtract := [][]map[string]interface{}{}
|
|
|
|
-
|
|
|
|
- //构建当前组的数据池
|
|
|
|
log.Println("构建第", k, "组---(数据池)")
|
|
log.Println("构建第", k, "组---(数据池)")
|
|
//当前组的第一个发布时间
|
|
//当前组的第一个发布时间
|
|
first_pt := util.Int64All(v[len(v)-1]["publishtime"])
|
|
first_pt := util.Int64All(v[len(v)-1]["publishtime"])
|
|
@@ -165,94 +159,94 @@ func historyRepeat() {
|
|
for _, tmp := range v {
|
|
for _, tmp := range v {
|
|
info := NewInfo(tmp)
|
|
info := NewInfo(tmp)
|
|
b, source, reason := curTM.check(info)
|
|
b, source, reason := curTM.check(info)
|
|
- if b { //有重复,生成更新语句,更新抽取和更新招标
|
|
|
|
|
|
+ if b { //有重复,更新
|
|
repeateN++
|
|
repeateN++
|
|
- //重复数据打标签
|
|
|
|
- repeat_ids:=source.repeat_ids
|
|
|
|
- repeat_ids = append(repeat_ids,info.id)
|
|
|
|
- source.repeat_ids = repeat_ids
|
|
|
|
-
|
|
|
|
updatelock.Lock()
|
|
updatelock.Lock()
|
|
- //替换数据池-更新
|
|
|
|
- curTM.replacePoolData(source)
|
|
|
|
- //更新数据源
|
|
|
|
- //判断是否在当前段落
|
|
|
|
- if judgeIsCurIds(gtid,lteid,source.id) {
|
|
|
|
- Update.updatePool <- []map[string]interface{}{//重复数据打标签
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "_id": StringTOBsonId(source.id),
|
|
|
|
- },
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "$set": map[string]interface{}{
|
|
|
|
- "repeat_ids": repeat_ids,
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
|
|
+ if judgeIsReplaceInfo(source.href, info.href) {
|
|
|
|
+ temp_source_id := source.id
|
|
|
|
+ temp_info_id := info.id
|
|
|
|
+ temp_source := info
|
|
|
|
+ temp_source.id = temp_source_id
|
|
|
|
+ curTM.replacePoolData(temp_source)
|
|
|
|
+ //替换抽取表数据
|
|
|
|
+ is_log, is_exists, ext_s_data, ext_i_data := confrimHistoryExtractData(temp_source_id, temp_info_id)
|
|
|
|
+ is_bid, bid_s_data, bid_i_data := confrimBiddingData(temp_source_id, temp_info_id)
|
|
|
|
+
|
|
|
|
+ if is_log && is_bid {
|
|
|
|
+ data_mgo.Save(extract_log, map[string]interface{}{
|
|
|
|
+ "_id": StringTOBsonId(temp_info_id),
|
|
|
|
+ "replace_id": temp_source_id,
|
|
|
|
+ "is_history": 1,
|
|
|
|
+ })
|
|
|
|
+ ext_s_data["repeat"] = 0
|
|
|
|
+ ext_s_data["dataging"] = 0
|
|
|
|
+ ext_i_data["repeat"] = 1
|
|
|
|
+ ext_i_data["repeat_id"] = temp_source_id
|
|
|
|
+ ext_i_data["repeat_reason"] = reason
|
|
|
|
+ ext_i_data["dataging"] = 0
|
|
|
|
+ ext_i_data["history_updatetime"] = qu.Int64All(time.Now().Unix())
|
|
|
|
+ if is_exists {
|
|
|
|
+ data_mgo.DeleteById(extract, temp_source_id)
|
|
|
|
+ data_mgo.Save(extract, ext_s_data)
|
|
|
|
+ } else {
|
|
|
|
+ data_mgo.DeleteById(extract_back, temp_source_id)
|
|
|
|
+ data_mgo.Save(extract_back, ext_s_data)
|
|
|
|
+ }
|
|
|
|
+ data_mgo.DeleteById(extract, temp_info_id)
|
|
|
|
+ data_mgo.Save(extract, ext_i_data)
|
|
|
|
+
|
|
|
|
+ task_mgo.DeleteById(task_bidding, temp_source_id)
|
|
|
|
+ task_mgo.Save(task_bidding, bid_s_data)
|
|
|
|
+ task_mgo.DeleteById(task_bidding, temp_info_id)
|
|
|
|
+ task_mgo.Save(task_bidding, bid_i_data)
|
|
|
|
+
|
|
|
|
+ //通道填充数据
|
|
|
|
+ msg := "id=" + temp_source_id
|
|
|
|
+ _ = MP.Publish(msg)
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("替换~相关表~未查询到数据~", temp_source_id, "~", temp_info_id)
|
|
}
|
|
}
|
|
- }else {
|
|
|
|
- groupOtherExtract = append(groupOtherExtract, []map[string]interface{}{//重复数据打标签
|
|
|
|
|
|
+ } else {
|
|
|
|
+ Update.updatePool <- []map[string]interface{}{ //重复数据打标签
|
|
map[string]interface{}{
|
|
map[string]interface{}{
|
|
- "_id": StringTOBsonId(source.id),
|
|
|
|
|
|
+ "_id": tmp["_id"],
|
|
},
|
|
},
|
|
map[string]interface{}{
|
|
map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
- "repeat_ids": repeat_ids,
|
|
|
|
|
|
+ "repeat": 1,
|
|
|
|
+ "repeat_reason": reason,
|
|
|
|
+ "repeat_id": source.id,
|
|
|
|
+ "dataging": 0,
|
|
|
|
+ "history_updatetime": util.Int64All(time.Now().Unix()),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
- })
|
|
|
|
- }
|
|
|
|
- Update.updatePool <- []map[string]interface{}{//重复数据打标签
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "_id": tmp["_id"],
|
|
|
|
- },
|
|
|
|
- map[string]interface{}{
|
|
|
|
- "$set": map[string]interface{}{
|
|
|
|
- "repeat": 1,
|
|
|
|
- "repeat_reason": reason,
|
|
|
|
- "repeat_id": source.id,
|
|
|
|
- "dataging": 0,
|
|
|
|
- "history_updatetime":util.Int64All(time.Now().Unix()),
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- if len(groupOtherExtract) >= 500 {
|
|
|
|
- data_mgo.UpSertBulk(extract_back, groupOtherExtract...)
|
|
|
|
- groupOtherExtract = [][]map[string]interface{}{}
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
updatelock.Unlock()
|
|
updatelock.Unlock()
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
- Update.updatePool <- []map[string]interface{}{//重复数据打标签
|
|
|
|
|
|
+ Update.updatePool <- []map[string]interface{}{ //重复数据打标签
|
|
map[string]interface{}{
|
|
map[string]interface{}{
|
|
"_id": tmp["_id"],
|
|
"_id": tmp["_id"],
|
|
},
|
|
},
|
|
map[string]interface{}{
|
|
map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
"$set": map[string]interface{}{
|
|
- "dataging": 0, //符合条件的都为dataging==0
|
|
|
|
- "history_updatetime":util.Int64All(time.Now().Unix()),
|
|
|
|
|
|
+ "dataging": 0, //符合条件的都为dataging==0
|
|
|
|
+ "history_updatetime": util.Int64All(time.Now().Unix()),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //每组数据结束-更新数据
|
|
|
|
- updatelock.Lock()
|
|
|
|
- if len(groupOtherExtract) > 0 {
|
|
|
|
- data_mgo.UpSertBulk(extract_back, groupOtherExtract...)
|
|
|
|
- }
|
|
|
|
- updatelock.Unlock()
|
|
|
|
-
|
|
|
|
}(k, v)
|
|
}(k, v)
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
|
|
- log.Println("this timeTask over.", n, "repeateN:", repeateN,gtid,lteid)
|
|
|
|
|
|
+ log.Println("this timeTask over.", n, "repeateN:", repeateN, gtid, lteid)
|
|
|
|
|
|
time.Sleep(30 * time.Second)
|
|
time.Sleep(30 * time.Second)
|
|
//任务完成,开始发送广播通知下面节点 发udp 去升索引待定 + 合并
|
|
//任务完成,开始发送广播通知下面节点 发udp 去升索引待定 + 合并
|
|
- if gtid!=lteid{
|
|
|
|
|
|
+ if gtid != lteid {
|
|
for _, to := range nextNode {
|
|
for _, to := range nextNode {
|
|
next_sid := util.BsonIdToSId(gtid)
|
|
next_sid := util.BsonIdToSId(gtid)
|
|
next_eid := util.BsonIdToSId(lteid)
|
|
next_eid := util.BsonIdToSId(lteid)
|
|
@@ -273,36 +267,38 @@ func historyRepeat() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- end:=time.Now().Unix()
|
|
|
|
|
|
+ end := time.Now().Unix()
|
|
|
|
|
|
- log.Println(gtid,lteid)
|
|
|
|
|
|
+ log.Println(gtid, lteid)
|
|
|
|
|
|
- if end-start<60*5 {
|
|
|
|
|
|
+ if end-start < 60*5 {
|
|
log.Println("睡眠.............")
|
|
log.Println("睡眠.............")
|
|
time.Sleep(5 * time.Minute)
|
|
time.Sleep(5 * time.Minute)
|
|
}
|
|
}
|
|
log.Println("继续下一段的历史判重")
|
|
log.Println("继续下一段的历史判重")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
//判断是否在当前id段落
|
|
//判断是否在当前id段落
|
|
-func judgeIsCurIds (gtid string,lteid string,curid string) bool {
|
|
|
|
|
|
+func judgeIsCurIds(gtid string, lteid string, curid string) bool {
|
|
|
|
|
|
gt_time, _ := strconv.ParseInt(gtid[:8], 16, 64)
|
|
gt_time, _ := strconv.ParseInt(gtid[:8], 16, 64)
|
|
lte_time, _ := strconv.ParseInt(lteid[:8], 16, 64)
|
|
lte_time, _ := strconv.ParseInt(lteid[:8], 16, 64)
|
|
cur_time, _ := strconv.ParseInt(curid[:8], 16, 64)
|
|
cur_time, _ := strconv.ParseInt(curid[:8], 16, 64)
|
|
- if cur_time>=gt_time&&cur_time<=lte_time {
|
|
|
|
|
|
+ if cur_time >= gt_time && cur_time <= lte_time {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
+
|
|
//迁移上一段数据
|
|
//迁移上一段数据
|
|
-func moveHistoryData(startid string,endid string) {
|
|
|
|
|
|
+func moveHistoryData(startid string, endid string) {
|
|
sess := data_mgo.GetMgoConn()
|
|
sess := data_mgo.GetMgoConn()
|
|
defer data_mgo.DestoryMongoConn(sess)
|
|
defer data_mgo.DestoryMongoConn(sess)
|
|
year, month, day := time.Now().Date()
|
|
year, month, day := time.Now().Date()
|
|
q := map[string]interface{}{
|
|
q := map[string]interface{}{
|
|
"_id": map[string]interface{}{
|
|
"_id": map[string]interface{}{
|
|
- "$gt": StringTOBsonId(startid),
|
|
|
|
|
|
+ "$gt": StringTOBsonId(startid),
|
|
"$lte": StringTOBsonId(endid),
|
|
"$lte": StringTOBsonId(endid),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
@@ -320,7 +316,7 @@ func moveHistoryData(startid string,endid string) {
|
|
|
|
|
|
qv := map[string]interface{}{
|
|
qv := map[string]interface{}{
|
|
"comeintime": map[string]interface{}{
|
|
"comeintime": map[string]interface{}{
|
|
- "$lt": time.Date(year, month, day, 0, 0, 0, 0, time.Local).Add(-time.Duration(dupdays+1) * 24 * time.Hour*2).Unix(),
|
|
|
|
|
|
+ "$lt": time.Date(year, month, day, 0, 0, 0, 0, time.Local).Add(-time.Duration(dupdays+1) * 24 * time.Hour * 2).Unix(),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
delnum := data_mgo.Delete(extract, qv)
|
|
delnum := data_mgo.Delete(extract, qv)
|
|
@@ -328,25 +324,18 @@ func moveHistoryData(startid string,endid string) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
//暂时弃用
|
|
//暂时弃用
|
|
-func moveTimeoutData() {
|
|
|
|
|
|
+func moveTimeoutData() {
|
|
log.Println("部署迁移定时任务")
|
|
log.Println("部署迁移定时任务")
|
|
c := cron.New()
|
|
c := cron.New()
|
|
c.AddFunc("0 0 0 * * ?", func() { moveOnceTimeOut() })
|
|
c.AddFunc("0 0 0 * * ?", func() { moveOnceTimeOut() })
|
|
c.Start()
|
|
c.Start()
|
|
}
|
|
}
|
|
-func moveOnceTimeOut() {
|
|
|
|
|
|
+func moveOnceTimeOut() {
|
|
log.Println("执行一次迁移超时数据")
|
|
log.Println("执行一次迁移超时数据")
|
|
sess := data_mgo.GetMgoConn()
|
|
sess := data_mgo.GetMgoConn()
|
|
defer data_mgo.DestoryMongoConn(sess)
|
|
defer data_mgo.DestoryMongoConn(sess)
|
|
- now:=time.Now()
|
|
|
|
|
|
+ now := time.Now()
|
|
|
|
|
|
move_time := time.Date(now.Year()-2, now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
|
move_time := time.Date(now.Year()-2, now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
|
task_id := util.BsonIdToSId(bson.NewObjectIdWithTime(move_time))
|
|
task_id := util.BsonIdToSId(bson.NewObjectIdWithTime(move_time))
|
|
@@ -362,9 +351,9 @@ func moveOnceTimeOut() {
|
|
if index%10000 == 0 {
|
|
if index%10000 == 0 {
|
|
log.Println("index", index)
|
|
log.Println("index", index)
|
|
}
|
|
}
|
|
- del_id:=BsonTOStringId(tmp["_id"])
|
|
|
|
|
|
+ del_id := BsonTOStringId(tmp["_id"])
|
|
data_mgo.Save("result_20200713", tmp)
|
|
data_mgo.Save("result_20200713", tmp)
|
|
- data_mgo.DeleteById("result_20200714",del_id)
|
|
|
|
|
|
+ data_mgo.DeleteById("result_20200714", del_id)
|
|
tmp = map[string]interface{}{}
|
|
tmp = map[string]interface{}{}
|
|
}
|
|
}
|
|
log.Println("save and delete", " ok index", index)
|
|
log.Println("save and delete", " ok index", index)
|