parallel optimization groundwork

This commit is contained in:
LPF
2026-05-10 17:27:06 +08:00
parent ce2263ac8c
commit 7b07bb270b
37 changed files with 6896 additions and 3481 deletions

View File

@@ -35,7 +35,15 @@ func (mb *MessageBus) PublishInbound(msg InboundMessage) {
select {
case mb.inbound <- msg:
case <-time.After(queueWriteTimeout):
return
default:
}
timer := time.NewTimer(queueWriteTimeout)
defer stopAndDrainTimer(timer)
select {
case mb.inbound <- msg:
case <-timer.C:
logger.ErrorCF("bus", logger.C0130, map[string]interface{}{
logger.FieldChannel: msg.Channel,
logger.FieldChatID: msg.ChatID,
@@ -62,7 +70,15 @@ func (mb *MessageBus) PublishOutbound(msg OutboundMessage) {
select {
case mb.outbound <- msg:
case <-time.After(queueWriteTimeout):
return
default:
}
timer := time.NewTimer(queueWriteTimeout)
defer stopAndDrainTimer(timer)
select {
case mb.outbound <- msg:
case <-timer.C:
logger.ErrorCF("bus", logger.C0132, map[string]interface{}{
logger.FieldChannel: msg.Channel,
logger.FieldChatID: msg.ChatID,
@@ -70,6 +86,19 @@ func (mb *MessageBus) PublishOutbound(msg OutboundMessage) {
}
}
func stopAndDrainTimer(timer *time.Timer) {
if timer == nil {
return
}
if timer.Stop() {
return
}
select {
case <-timer.C:
default:
}
}
func (mb *MessageBus) SubscribeOutbound(ctx context.Context) (OutboundMessage, bool) {
select {
case msg, ok := <-mb.outbound: