From 9e3850805f50fbb25cc656079c3715d87af2a3d7 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Mon, 14 Dec 2020 01:28:05 +0800 Subject: [PATCH] save --- collect.go | 22 ++++++++++++---------- global.go | 2 ++ go.mod | 3 +-- go.sum | 6 ++---- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/collect.go b/collect.go index 99b31b7..e095584 100644 --- a/collect.go +++ b/collect.go @@ -2,12 +2,13 @@ package main import ( "context" + "database/sql" "encoding/json" + "fmt" "log" "time" mongodb "git.nonolive.co/eson.hsm/databoard-collect/database" - database "git.nonolive.co/eson.hsm/databoard-database-myrocks" "github.com/go-sql-driver/mysql" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -20,17 +21,18 @@ func collectCopyCountLiveAnchors(cxt *WorkerContext) { for !ps.IsClose() { - db.Do(func(T *database.TableManager) { + db.Do(func(db *sql.DB) { liveanchor := &CountLiveAnchors{} - T.CountLiveAnchors.Order("create_at desc").Limit(1).Find(liveanchor) - if err = T.CountLiveAnchors.Error; err == nil { + // T.CountLiveAnchors.Order("create_at desc").Limit(1).Find(liveanchor) + selectsql := fmt.Sprintf("select uid, create_at from %s order by create_at desc limit 1", Tables.CountLiveAnchors) + row := db.QueryRow(selectsql) + if row.Err() == nil { + + row.Scan(&liveanchor.UID, &liveanchor.CreateAt) + log.Println("last: ", liveanchor.CreateAt, liveanchor.UID) + var cur *mongo.Cursor - var last time.Time - last = liveanchor.CreateAt - - log.Println("last: ", last, liveanchor.UID) - - cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": last}}) + cur, err = mdb.C.CountLiveAnchors.Find(context.TODO(), bson.M{"create_at": bson.M{"$gt": liveanchor.CreateAt}}) if err != nil { log.Println(err) ps.Wait(time.Second * 5) diff --git a/global.go b/global.go index 925a27d..b9c9056 100644 --- a/global.go +++ b/global.go @@ -13,3 +13,5 @@ var mdb = mongodb.NewStatisticsDB("mongodb://sg-board1.livenono.com:27018") // 默认全局的数据库对象 var db = myrocks.DB + +var Tables = myrocks.Tables diff --git a/go.mod b/go.mod index 07dc108..bfa7914 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,8 @@ go 1.15 require ( git.nonolive.co/eson.hsm/databoard-collect v0.3.0 - git.nonolive.co/eson.hsm/databoard-database-myrocks v0.1.0 + git.nonolive.co/eson.hsm/databoard-database-myrocks v0.2.2 github.com/474420502/perfectshutdown v0.1.0 github.com/go-sql-driver/mysql v1.5.0 - github.com/go-xorm/xorm v0.7.9 go.mongodb.org/mongo-driver v1.4.3 ) diff --git a/go.sum b/go.sum index 8589da4..2cbc4bb 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,8 @@ git.nonolive.co/eson.hsm/databoard-collect v0.3.0 h1:fy3SJFR2QOoLRjfKSqHeQMjp90q git.nonolive.co/eson.hsm/databoard-collect v0.3.0/go.mod h1:KX2Se020AIewrmc9k3SotNHT3S+yGFQnPmcEvRa3Za0= git.nonolive.co/eson.hsm/databoard-database-myrocks v0.1.0 h1:/N2ThrAvlbdGzjaogP4n9ShnnWuyxZb2yVwC7Vrg/eg= git.nonolive.co/eson.hsm/databoard-database-myrocks v0.1.0/go.mod h1:SNP2vUXs6aCLLwSkTzfNp/6QnAfPNKSaQ+Di3ZnmaWw= -git.nonolive.co/eson.hsm/databoard-database-myrocks v0.2.0 h1:65TeCdNIZ/TqV9BYQSrq41qcut7KOu1s0Beww3txSh4= -git.nonolive.co/eson.hsm/databoard-database-myrocks v0.2.0/go.mod h1:SNP2vUXs6aCLLwSkTzfNp/6QnAfPNKSaQ+Di3ZnmaWw= -git.nonolive.co/eson.hsm/databoard-database-myrocks v0.2.1 h1:0zAwFTt0gb46jAHppitm2QB6jag+2qZ7U1xhKpu0Pn0= -git.nonolive.co/eson.hsm/databoard-database-myrocks v0.2.1/go.mod h1:SNP2vUXs6aCLLwSkTzfNp/6QnAfPNKSaQ+Di3ZnmaWw= +git.nonolive.co/eson.hsm/databoard-database-myrocks v0.2.2 h1:vsEZVsobeDKoMvGJxzei83gLQoRIn2KA0c63TgqoAuo= +git.nonolive.co/eson.hsm/databoard-database-myrocks v0.2.2/go.mod h1:SNP2vUXs6aCLLwSkTzfNp/6QnAfPNKSaQ+Di3ZnmaWw= github.com/474420502/perfectshutdown v0.1.0 h1:xffrGHi0ZgAwy6N0y6DJ6xoo2kpTt4Hktg9rTgSN8ys= github.com/474420502/perfectshutdown v0.1.0/go.mod h1:qonD0eLCz1ncQq8heGQHbPdLlh30lofF2ISzV5ASW8A= github.com/474420502/requests v1.9.1/go.mod h1:x2T9l+e40R6kxxMvNm+YSZ9D6BHAXUDak4kQElIPJ9A=