add timestamp before publishing events

This commit is contained in:
Radu Ioan Fericean
2015-10-20 12:45:13 +03:00
parent 97db6971db
commit ec6531e2d3
2 changed files with 2 additions and 1 deletions

View File

@@ -122,6 +122,7 @@ func (ps *PubSub) Unsubscribe(si SubscribeInfo, reply *string) error {
func (ps *PubSub) Publish(evt CgrEvent, reply *string) error {
ps.mux.Lock()
defer ps.mux.Unlock()
evt["Timestamp"] = time.Now().Format(time.RFC3339Nano)
for key, subData := range ps.subscribers {
if !subData.ExpTime.IsZero() && subData.ExpTime.Before(time.Now()) {
delete(ps.subscribers, key)

View File

@@ -137,7 +137,7 @@ func TestPublish(t *testing.T) {
t.Error("Error publishing: ", err)
}
for i := 0; i < 1000; i++ { // wait for the theread to populate map
if len(m) == 1 {
if len(m) == 2 {
time.Sleep(time.Microsecond)
} else {
break