diff --git a/collect.go b/collect.go index f4f13e5..01272d4 100644 --- a/collect.go +++ b/collect.go @@ -16,20 +16,28 @@ import ( func collectCopyCountLiveAnchors(cxt *WorkerContext) { defer cxt.Done() + var err error + var ok bool for !ps.IsClose() { liveanchor := &CountLiveAnchors{} - ok, err := db.T.CountLiveAnchors.OrderBy("create_at desc").Limit(1).Get(liveanchor) + ok, err = db.T.CountLiveAnchors.OrderBy("create_at desc").Limit(1).Get(liveanchor) if ok || (ok == false && err == nil) { var cur *mongo.Cursor + var last time.Time if ok == false { - cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": "2020-05-30"}}) + last, err = time.ParseInLocation("2006-01-02", "2020-05-30", time.Local) + if err != nil { + panic(err) + } + cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": last}}) } else { - last := liveanchor.CreateAt + last = liveanchor.CreateAt log.Println("last: ", last) cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": last}}) } + if err != nil { log.Println(err) ps.Wait(time.Second * 5)