作者 yangfu

互动消息 机会补充

... ... @@ -10,6 +10,7 @@ import (
"reflect"
"strconv"
"strings"
"time"
)
// 此函数将指定的结构体成员值更新到结构体中
... ... @@ -121,3 +122,13 @@ func ValidVersion(current, compare string) bool {
}
return false
}
// 统计某函数执行时间
// 使用方式
// defer utils.Profiling("test")()
func Profiling(msg string) func() {
start := time.Now()
return func() {
log.Info(fmt.Sprintf("%s[%s]:%s", msg, "use", time.Since(start)))
}
}
... ...
... ... @@ -91,6 +91,8 @@ func main() {
//beego.BConfig.Listen.HTTPSPort = 8089
//beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt"
//beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key"
//contrab.Run()
beego.Run()
}
... ...
... ... @@ -251,8 +251,8 @@ select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at
select id msg_id,message content,source_type,source_id,is_read,create_at msg_time,chance_id,receive_user_id,sender_user_id from user_msg
where receive_user_id =? and (?=0 or id<?) and msg_type=?
)a left outer join chance b on a.chance_id = b.id
)a left outer join chance_data b on a.source_id = b.chance_id
order by id
)a left outer join chance_data b on a.chance_id = b.chance_id
order by id desc
LIMIT ?`
sqlCount := `select count(0)
... ...
package contrab
import "github.com/astaxie/beego/toolbox"
var (
taskComputeRankScore = "0 5 0 * * *" //每0:5分 计算排行榜分数
)
func Run() {
taskRank := toolbox.NewTask("taskComputeRankScore", taskComputeRankScore, ComputeRankScore)
toolbox.AddTask("taskComputeRankScore", taskRank)
toolbox.StartTask()
}
... ...
package contrab
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/utils"
"sync/atomic"
"time"
)
var ComputeRankScoreFlag int32
type Rank interface {
RankUser(o RankOption) error
RankDepartment(o RankOption) error
}
type RankOption struct {
BeginTime time.Time
EndTime time.Time
}
//计算排行分
func ComputeRankScore() error {
defer func() {
if p := recover(); p != nil {
log.Error(p)
}
}()
if !atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 0, 1) {
return fmt.Errorf("ComputeRankScore is working. try later")
} else {
defer utils.Profiling("ComputeRankScore 执行耗时")()
}
defer func() {
atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0)
}()
return computeRankScore()
}
func computeRankScore() error {
return nil
}
... ...