1
0
Fork 0
mirror of https://github.com/Luzifer/nginx-sso.git synced 2024-12-21 05:11:17 +00:00
nginx-sso/vendor/cloud.google.com/go/pubsub/debug.go

73 lines
1.5 KiB
Go
Raw Normal View History

// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build psdebug
package pubsub
import (
"sync"
"time"
)
var (
dmu sync.Mutex
msgTraces = map[string][]Event{}
ackIDToMsgID = map[string]string{}
)
type Event struct {
Desc string
At time.Time
}
func MessageEvents(msgID string) []Event {
dmu.Lock()
defer dmu.Unlock()
return msgTraces[msgID]
}
func addRecv(msgID, ackID string, t time.Time) {
dmu.Lock()
defer dmu.Unlock()
ackIDToMsgID[ackID] = msgID
addEvent(msgID, "recv", t)
}
func addAcks(ackIDs []string) {
dmu.Lock()
defer dmu.Unlock()
now := time.Now()
for _, id := range ackIDs {
addEvent(ackIDToMsgID[id], "ack", now)
}
}
func addModAcks(ackIDs []string, deadlineSecs int32) {
dmu.Lock()
defer dmu.Unlock()
desc := "modack"
if deadlineSecs == 0 {
desc = "nack"
}
now := time.Now()
for _, id := range ackIDs {
addEvent(ackIDToMsgID[id], desc, now)
}
}
func addEvent(msgID, desc string, t time.Time) {
msgTraces[msgID] = append(msgTraces[msgID], Event{desc, t})
}