|
@@ -20,6 +20,8 @@ type LuaMove struct {
|
|
|
*xweb.Action
|
|
|
luaMove xweb.Mapper `xweb:"/center/luamove"` //站点列表
|
|
|
luaMoveByCode xweb.Mapper `xweb:"/center/luamove/luamovebycode"` //
|
|
|
+ closeAll xweb.Mapper `xweb:"/center/luamove/closeall"` //关闭所有爬虫
|
|
|
+ updateToEvent xweb.Mapper `xweb:"/center/luamove/updatetoevent"` //更新目标节点
|
|
|
}
|
|
|
|
|
|
func (lm *LuaMove) LuaMove() {
|
|
@@ -114,7 +116,8 @@ func (lm *LuaMove) LuaMoveByCode() {
|
|
|
map[string]interface{}{"code": code},
|
|
|
map[string]interface{}{
|
|
|
"$set": map[string]interface{}{
|
|
|
- "state": 1,
|
|
|
+ "state": 1,
|
|
|
+ "updatetime": time.Now().Unix(),
|
|
|
},
|
|
|
},
|
|
|
})
|
|
@@ -125,6 +128,21 @@ func (lm *LuaMove) LuaMoveByCode() {
|
|
|
lm.ServeJson(map[string]interface{}{"ok": ok})
|
|
|
}
|
|
|
|
|
|
+func (lm *LuaMove) CloseAll() {
|
|
|
+ defer qu.Catch()
|
|
|
+ ok := u.MgoEB.Update("luamovevent", map[string]interface{}{"state": 0}, map[string]interface{}{"$set": map[string]interface{}{"state": 1, "updatetime": time.Now().Unix()}}, false, true)
|
|
|
+ lm.ServeJson(map[string]interface{}{"ok": ok})
|
|
|
+}
|
|
|
+
|
|
|
+func (lm *LuaMove) UpdateToEvent() {
|
|
|
+ defer qu.Catch()
|
|
|
+ id := lm.GetString("id")
|
|
|
+ event, _ := lm.GetInteger("event")
|
|
|
+ qu.Debug(id, event)
|
|
|
+ ok := u.MgoEB.UpdateById("luamovevent", id, map[string]interface{}{"$set": map[string]interface{}{"toevent": event, "updatetime": time.Now().Unix()}})
|
|
|
+ lm.ServeJson(map[string]interface{}{"ok": ok})
|
|
|
+}
|
|
|
+
|
|
|
//爬虫迁移
|
|
|
func SpiderMoveLua(codes []string, events []string) bool {
|
|
|
defer qu.Catch()
|
|
@@ -135,16 +153,16 @@ func SpiderMoveLua(codes []string, events []string) bool {
|
|
|
lua, _ := u.MgoEB.FindOne("luaconfig", map[string]interface{}{"code": code})
|
|
|
if len(*lua) > 0 {
|
|
|
state := qu.IntAll((*lua)["state"])
|
|
|
- //event := qu.IntAll((*lua)["event"])
|
|
|
+ event := qu.IntAll((*lua)["event"])
|
|
|
if state == 5 { //查询该爬虫是否是已上架状态,是则更新节点后上架,否则只更新
|
|
|
upresult := true
|
|
|
var err interface{}
|
|
|
- //upresult, err = spider.UpdateSpiderByCodeState(code, "6", event) //脚本下架
|
|
|
- if upresult && err == nil { //下架成功,更新节点
|
|
|
+ upresult, err = spider.UpdateSpiderByCodeState(code, "6", event) //脚本下架
|
|
|
+ if upresult && err == nil { //下架成功,更新节点
|
|
|
re := qu.IntAll(resultEvent)
|
|
|
u.MgoEB.Update("luaconfig", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"event": re, "historyevent": re}}, false, false)
|
|
|
//上架
|
|
|
- //upresult, err = spider.UpdateSpiderByCodeState(code, "5",re) //脚本上架
|
|
|
+ upresult, err = spider.UpdateSpiderByCodeState(code, "5", re) //脚本上架
|
|
|
if !upresult || err != nil {
|
|
|
qu.Debug("爬虫节点转移", code, "上架失败")
|
|
|
msg = append(msg, "爬虫节点转移"+code+"上架失败")
|
|
@@ -154,7 +172,7 @@ func SpiderMoveLua(codes []string, events []string) bool {
|
|
|
msg = append(msg, "爬虫节点转移"+code+"下架失败")
|
|
|
}
|
|
|
}
|
|
|
- u.MgoEB.Update("luamovevent", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"state": 1}}, false, false)
|
|
|
+ u.MgoEB.Update("luamovevent", map[string]interface{}{"code": code}, map[string]interface{}{"$set": map[string]interface{}{"state": 1, "updatetime": time.Now().Unix()}}, false, false)
|
|
|
} else {
|
|
|
msg = append(msg, "爬虫节点转移未找到爬虫"+code)
|
|
|
}
|