Skip to content

Commit

Permalink
Optimize the event json struct to nsq
Browse files Browse the repository at this point in the history
  • Loading branch information
sols1st committed Mar 24, 2024
1 parent 0f94b39 commit e651000
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions util/event-action.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,30 @@ func (eh *eventActionHandler) Handle() model.EventLog {
} else {
eventLog = eh.createEventLog(createEventLogArgs{})
}
logger := getLogger()
if producer := GetNSQProducer(); producer != nil {
mapEventLog := map[string]interface{}{
"event_id": eventLog.EventId,
"action": eventLog.Action,
"member_id": eventLog.MemberId,
"gmt_create": eventLog.GmtCreate,
"description": eventLog.Description,
"data": eh.event,
}
jsonMap, _ := json.Marshal(mapEventLog)
producer.PublishAsync(EventTopic, jsonMap, nil)
// logger.Hooks.Add(&NSQHookForEvent{
// Producer: producer,
// })
}
logger.WithFields(logrus.Fields{

Logger.WithFields(logrus.Fields{
"event_id": eventLog.EventId,
"action": eventLog.Action,
"member_id": eventLog.MemberId,
"gmt_create": eventLog.GmtCreate,
"description": eventLog.Description,
}).Info("new event action")

if producer := GetNSQProducer(); producer != nil {
mapEventLog := map[string]interface{}{
"event_id": eventLog.EventId,
"action": eventLog.Action,
"member_id": eventLog.MemberId,
"member_alias": eh.event.Member.Alias,
"problem": eh.event.Problem,
"model": eh.event.Model,
"gmt_create": eventLog.GmtCreate,
"description": eventLog.Description,
}
jsonMap, _ := json.Marshal(mapEventLog)
producer.PublishAsync(EventTopic, jsonMap, nil)
}

return eventLog
}

Expand Down

0 comments on commit e651000

Please sign in to comment.