mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-10 11:13:44 +08:00
更新2.1.2版本,优化部门、角色权限,增加上下级关系;增加登录、系统、短信日志;优化省市区编码
This commit is contained in:
@@ -8,22 +8,63 @@ package queues
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/library/queue"
|
||||
)
|
||||
|
||||
type jobStrategy interface {
|
||||
Listen(ctx context.Context)
|
||||
getTopic() string
|
||||
handle(ctx context.Context, mqMsg queue.MqMsg) (err error)
|
||||
}
|
||||
|
||||
var (
|
||||
jobList = []jobStrategy{
|
||||
SysLog,
|
||||
}
|
||||
)
|
||||
var jobList []jobStrategy
|
||||
|
||||
func Run(ctx context.Context) {
|
||||
for _, job := range jobList {
|
||||
job.Listen(ctx)
|
||||
for _, job := range uniqueJob(jobList) {
|
||||
go func(job jobStrategy) {
|
||||
listen(ctx, job)
|
||||
}(job)
|
||||
}
|
||||
}
|
||||
|
||||
func listen(ctx context.Context, job jobStrategy) {
|
||||
var (
|
||||
topic = job.getTopic()
|
||||
consumer, err = queue.InstanceConsumer()
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
g.Log().Fatalf(ctx, "InstanceConsumer %s err:%+v", topic, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 访问日志
|
||||
if listenErr := consumer.ListenReceiveMsgDo(topic, func(mqMsg queue.MqMsg) {
|
||||
err = job.handle(ctx, mqMsg)
|
||||
|
||||
if err != nil {
|
||||
// 遇到错误,重新加入到队列
|
||||
//queue.Push(topic, mqMsg.Body)
|
||||
}
|
||||
|
||||
// 记录队列日志
|
||||
queue.ConsumerLog(ctx, topic, mqMsg, err)
|
||||
|
||||
}); listenErr != nil {
|
||||
g.Log().Fatalf(ctx, "队列:%s 监听失败, err:%+v", topic, listenErr)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// uniqueJob 去重
|
||||
func uniqueJob(languages []jobStrategy) []jobStrategy {
|
||||
result := make([]jobStrategy, 0, len(languages))
|
||||
temp := map[jobStrategy]struct{}{}
|
||||
for _, item := range languages {
|
||||
if _, ok := temp[item]; !ok {
|
||||
temp[item] = struct{}{}
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user