Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
cc2946f0
Commit
cc2946f0
authored
Aug 24, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
队列
parent
32bd2d6a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
40 deletions
+83
-40
queue.go
_const/redis_key/mic_k/queue.go
+10
-0
cron.go
cron/cron.go
+2
-1
on_mic.go
cron/mic_cron/on_mic.go
+28
-2
queue.go
domain/cache/mic_c/queue.go
+41
-0
on_mic.go
domain/event/mic_ev/on_mic.go
+2
-0
event_init.go
domain/service/event_s/event_init.go
+0
-37
No files found.
_const/redis_key/mic_k/queue.go
0 → 100644
View file @
cc2946f0
package
mic_k
// onMic异步入库
const
(
OnMicQueue
=
"onMic:hilo_group"
)
func
GetOnMicQueue
()
string
{
return
OnMicQueue
}
cron/cron.go
View file @
cc2946f0
...
...
@@ -15,10 +15,11 @@ func Init() {
//gift_cron.GiftRemark() // 礼物消息补偿
gift_cron
.
SendGiftEvent
()
// 礼物事件
mic_cron
.
OnMicCheck
()
// 检查上麦
mic_cron
.
OnMicQueue
()
// 检查上麦-队列操作
group_cron
.
GroupPowerExpClear
()
// 清理家族经验/等级
group_cron
.
GroupPowerMonthRankAct
()
//group_cron.GroupInEventInit() // 进房事件
group_cron
.
GroupPowerGradeExp
()
// 家族升级(上麦事件会用到) todo
group_cron
.
GroupPowerGradeExp
()
// 家族升级(上麦事件会用到) todo
待优化
group_cron
.
CreateGroup
()
//
group_cron
.
CalcGroupSupport
()
// 群组扶持计算
}
cron/mic_cron/on_mic.go
View file @
cc2946f0
...
...
@@ -3,8 +3,11 @@ package mic_cron
import
(
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/cache/mic_c"
"hilo-group/domain/event/mic_ev"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/mic_m"
"hilo-group/domain/service/group_mic_s"
)
func
OnMicCheck
()
{
...
...
@@ -27,7 +30,7 @@ func OnMicCheck() {
model
.
Log
.
Errorf
(
"cron micIn group_m.GetMicUser err:%v"
,
err
)
}
if
micUser
!=
nil
{
if
err
:=
mic_
ev
.
PublishOnMicEvent
(
model
,
&
mic_ev
.
OnMicEvent
{
if
err
:=
mic_
c
.
QueueOnMic
(
model
,
&
mic_ev
.
OnMicEvent
{
GroupUuid
:
micUser
.
GroupUuid
,
I
:
micUser
.
I
,
ExternalId
:
micUser
.
ExternalId
,
...
...
@@ -35,7 +38,7 @@ func OnMicCheck() {
Forbid
:
micUser
.
Forbid
,
Timestamp
:
micUser
.
Timestamp
,
});
err
!=
nil
{
model
.
Log
.
Errorf
(
"
PublishOnMicEvent
fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"
QueueOnMic
fail:%v"
,
err
)
}
}
}
...
...
@@ -43,3 +46,26 @@ func OnMicCheck() {
})
c
.
Start
()
}
func
OnMicQueue
()
{
go
func
()
{
for
true
{
model
:=
domain
.
CreateModelNil
()
if
onMic
:=
mic_c
.
BLPopQueueOnMic
(
model
);
onMic
!=
nil
{
// 群组上麦经验
if
err
:=
group_mic_s
.
NewGroupPowerService
(
model
.
MyContext
)
.
IncrGroupPowerOnMicExpAndTime
(
onMic
.
GroupUuid
,
onMic
.
UserId
,
onMic
.
Timestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cron micIn GroupPowerOnMicExp err:%v"
,
err
)
}
else
{
model
.
Log
.
Infof
(
"cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v"
,
onMic
.
GroupUuid
,
onMic
.
UserId
)
}
// 用户上麦
if
err
:=
mic_m
.
IncrUserOnMic
(
model
,
onMic
.
UserId
,
onMic
.
Timestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cron micIn IncrUserOnMic err:%v"
,
err
)
}
else
{
model
.
Log
.
Infof
(
"cron micIn IncrUserOnMic success,userId:%v"
,
onMic
.
UserId
)
}
}
}
}()
}
domain/cache/mic_c/queue.go
0 → 100644
View file @
cc2946f0
package
mic_c
import
(
"encoding/json"
"git.hilo.cn/hilo-common/domain"
"github.com/go-redis/redis/v8"
"hilo-group/_const/redis_key/mic_k"
"hilo-group/domain/event/mic_ev"
"time"
)
// redis queue on mic
func
QueueOnMic
(
model
*
domain
.
Model
,
onMic
*
mic_ev
.
OnMicEvent
)
error
{
queue
:=
mic_k
.
GetOnMicQueue
()
onMic
.
Ts
=
time
.
Now
()
.
UnixNano
()
// 给一个时间戳
body
,
_
:=
json
.
Marshal
(
onMic
)
return
model
.
Redis
.
RPush
(
model
,
queue
,
string
(
body
))
.
Err
()
}
// redis pop on mic
func
BLPopQueueOnMic
(
model
*
domain
.
Model
)
*
mic_ev
.
OnMicEvent
{
var
res
*
mic_ev
.
OnMicEvent
queue
:=
mic_k
.
GetOnMicQueue
()
strs
,
err
:=
model
.
Redis
.
BLPop
(
model
,
time
.
Second
,
queue
)
.
Result
()
if
err
!=
nil
{
if
err
!=
redis
.
Nil
{
model
.
Log
.
Errorf
(
"BLPopQueueOnMic fail:%v"
,
err
)
}
return
nil
}
if
len
(
strs
)
>=
2
{
content
:=
strs
[
1
]
res
=
new
(
mic_ev
.
OnMicEvent
)
if
err
:=
json
.
Unmarshal
([]
byte
(
content
),
res
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"BLPopQueueOnMic json fail:%v"
,
err
)
return
nil
}
return
res
}
return
nil
}
domain/event/mic_ev/on_mic.go
View file @
cc2946f0
...
...
@@ -14,6 +14,8 @@ type OnMicEvent struct {
UserId
uint64
// 麦中的人
Forbid
bool
// 静音 true:静音,false:没有静音
Timestamp
int64
// 上麦的的时间戳
Ts
int64
}
func
AddOnMicEventSync
(
callback
func
(
model
*
domain
.
Model
,
event
interface
{})
error
)
{
...
...
domain/service/event_s/event_init.go
View file @
cc2946f0
...
...
@@ -12,15 +12,12 @@ import (
"hilo-group/domain/cache/group_c"
"hilo-group/domain/event/group_ev"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/event/mic_ev"
"hilo-group/domain/model/diamond_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/mic_m"
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/task_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_mic_s"
"hilo-group/myerr"
"strconv"
"time"
...
...
@@ -33,7 +30,6 @@ func EventInit() {
GroupImMass
()
GroupTheme
()
//SendGift() // 送礼事件
OnMic
()
// 在麦上事件
GroupInMicChangeEvent
()
// 用户进房推送mic位置信息
}
...
...
@@ -535,36 +531,3 @@ func SendGift() {
// return nil
//})
}
func
OnMic
()
{
// 上麦经验/上麦时长
mic_ev
.
AddOnMicEventAsync
(
func
(
model
*
domain
.
Model
,
e
interface
{})
error
{
event
,
ok
:=
e
.
(
*
mic_ev
.
OnMicEvent
)
if
!
ok
{
model
.
Log
.
Errorf
(
"AddOnMicEventSync event type err"
)
return
nil
}
if
err
:=
group_mic_s
.
NewGroupPowerService
(
model
.
MyContext
)
.
IncrGroupPowerOnMicExpAndTime
(
event
.
GroupUuid
,
event
.
UserId
,
event
.
Timestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cron micIn GroupPowerOnMicExp err:%v"
,
err
)
}
else
{
model
.
Log
.
Infof
(
"cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v"
,
event
.
GroupUuid
,
event
.
UserId
)
}
return
nil
})
// 用户上麦时长
mic_ev
.
AddOnMicEventAsync
(
func
(
model
*
domain
.
Model
,
e
interface
{})
error
{
event
,
ok
:=
e
.
(
*
mic_ev
.
OnMicEvent
)
if
!
ok
{
model
.
Log
.
Errorf
(
"AddOnMicEventSync event type err"
)
return
nil
}
if
err
:=
mic_m
.
IncrUserOnMic
(
model
,
event
.
UserId
,
event
.
Timestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cron micIn IncrUserOnMic err:%v"
,
err
)
}
else
{
model
.
Log
.
Infof
(
"cron micIn IncrUserOnMic success,userId:%v"
,
event
.
UserId
)
}
// 处理活动数据 活动已经结束
//go rpc.AddActPoint(model, event.UserId, 1, 0)
return
nil
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment