123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package task
- import (
- "fmt"
- "luaweb/front"
- mgdb "qfw/util/mongodb"
- "time"
- "gopkg.in/mgo.v2/bson"
- )
- var timer *time.Ticker
- func init() {
- timer = time.NewTicker(1 * time.Second)
- }
- func TimeTask() {
- for t := range timer.C {
- hour := t.Hour()
- second := t.Second()
- minutes := t.Minute()
- if hour == 0 && minutes == 0 && second == 0 {
- FlushAuthor()
- }
- }
- }
- func FlushAuthor() {
- query := bson.M{
- "flush": bson.M{"$exists": false},
- "next": bson.M{"$exists": true},
- "l_uploadtime": bson.M{
- "$lte": time.Now().AddDate(0, 0, -30).Unix(),
- },
- "$where": "this.createuseremail != this.next",
- }
- rets := *mgdb.Find("luaconfig", query, bson.M{}, bson.M{}, false, -1, -1)
- for _, v := range rets {
- next, ok := v["next"].(string)
- if ok {
- one := *mgdb.FindOne("user", bson.M{"s_email": next})
- if len(one) > 0 {
- update := bson.M{
- "$set": bson.M{
- "createuser": one["s_name"],
- "createuserid": one["_id"].(bson.ObjectId).Hex(),
- "createuseremail": next,
- "flush": "ok",
- },
- }
- front.Wlog("转移爬虫给", v["code"].(string), fmt.Sprint(one["s_name"]), next, "系统定时任务", nil)
- mgdb.Update("luaconfig", bson.M{"_id": v["_id"]}, update, false, false)
- }
- }
- }
- }
|