INFRA-3661 : Make Data fetch calls concurrent to avoid timeouts (#448)
This commit is contained in:
@@ -6,17 +6,21 @@ import (
|
||||
"github.com/slack-go/slack/socketmode"
|
||||
"go.uber.org/zap"
|
||||
"houston/appcontext"
|
||||
"houston/common"
|
||||
"houston/common/metrics"
|
||||
"houston/common/util"
|
||||
"houston/internal/processor/action/view"
|
||||
"houston/logger"
|
||||
"houston/model/incident"
|
||||
incidentStatusModel "houston/model/incidentStatus"
|
||||
severityModel "houston/model/severity"
|
||||
"houston/model/team"
|
||||
"houston/repository/severity"
|
||||
incidentStatusService "houston/service/incidentStatus"
|
||||
"houston/service/incidentUser"
|
||||
incidentUserRequest "houston/service/request/incidentUser"
|
||||
userService "houston/service/user"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type MemberJoinAction struct {
|
||||
@@ -55,6 +59,8 @@ func (mp *MemberJoinAction) PerformAction(memberJoinedChannelEvent *slackevents.
|
||||
return
|
||||
}
|
||||
|
||||
mp.postIncidentSummaryEphemeral(incidentEntity, memberJoinedChannelEvent)
|
||||
|
||||
go func() {
|
||||
err := mp.addIncidentUserMapping(incidentEntity.ID, memberJoinedChannelEvent.User)
|
||||
if err != nil {
|
||||
@@ -63,54 +69,94 @@ func (mp *MemberJoinAction) PerformAction(memberJoinedChannelEvent *slackevents.
|
||||
}
|
||||
}()
|
||||
|
||||
teamEntity, err := mp.teamService.FindTeamById(incidentEntity.TeamId)
|
||||
}
|
||||
|
||||
func (mp *MemberJoinAction) postIncidentSummaryEphemeral(
|
||||
incidentEntity *incident.IncidentEntity, memberJoinedChannelEvent *slackevents.MemberJoinedChannelEvent,
|
||||
) {
|
||||
var (
|
||||
responderTeam, reporterTeam *team.TeamEntity
|
||||
severityEntity *severityModel.SeverityEntity
|
||||
incidentStatus *incidentStatusModel.IncidentStatusDTO
|
||||
errors common.ThreadSafeErrors
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
|
||||
wg.Add(4)
|
||||
|
||||
go util.ExecuteConcurrentAction(&wg, func() {
|
||||
team, err := mp.teamService.FindTeamById(incidentEntity.TeamId)
|
||||
if err != nil {
|
||||
logger.Error("error in fetching team", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID), zap.Error(err))
|
||||
return
|
||||
} else if teamEntity == nil {
|
||||
errors.AddErrors(err)
|
||||
} else if team == nil {
|
||||
logger.Info("team not found", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID))
|
||||
return
|
||||
errors.AddErrors(fmt.Errorf("team not found"))
|
||||
} else {
|
||||
responderTeam = team
|
||||
}
|
||||
})
|
||||
|
||||
severityEntity, err := mp.severityService.FindSeverityById(incidentEntity.SeverityId)
|
||||
go util.ExecuteConcurrentAction(&wg, func() {
|
||||
severity, err := mp.severityService.FindSeverityById(incidentEntity.SeverityId)
|
||||
if err != nil {
|
||||
logger.Error("error in fetching severity", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID), zap.Error(err))
|
||||
return
|
||||
} else if severityEntity == nil {
|
||||
errors.AddErrors(err)
|
||||
} else if severity == nil {
|
||||
logger.Info("severity not found", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID))
|
||||
return
|
||||
errors.AddErrors(fmt.Errorf("severity not found"))
|
||||
} else {
|
||||
severityEntity = severity
|
||||
}
|
||||
})
|
||||
|
||||
incidentStatus, err := mp.incidentStatusService.GetIncidentStatusByStatusId(incidentEntity.Status)
|
||||
go util.ExecuteConcurrentAction(&wg, func() {
|
||||
status, err := mp.incidentStatusService.GetIncidentStatusByStatusId(incidentEntity.Status)
|
||||
if err != nil {
|
||||
logger.Error("error in fetching incident status", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID), zap.Error(err))
|
||||
return
|
||||
} else if incidentStatus == nil {
|
||||
errors.AddErrors(err)
|
||||
} else if status == nil {
|
||||
logger.Info("incident status not found", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID))
|
||||
return
|
||||
errors.AddErrors(fmt.Errorf("incident status not found"))
|
||||
} else {
|
||||
incidentStatus = status
|
||||
}
|
||||
})
|
||||
|
||||
var reportingTeamEntity *team.TeamEntity = nil
|
||||
go util.ExecuteConcurrentAction(&wg, func() {
|
||||
if incidentEntity.ReportingTeamId != nil {
|
||||
var err error
|
||||
reportingTeamEntity, err = mp.teamService.FindTeamById(*incidentEntity.ReportingTeamId)
|
||||
team, err := mp.teamService.FindTeamById(*incidentEntity.ReportingTeamId)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to get reporting team"), zap.Error(err))
|
||||
logger.Error("error in fetching reporting team", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID), zap.Error(err))
|
||||
errors.AddErrors(err)
|
||||
} else if team == nil {
|
||||
logger.Info("reporting team not found", zap.String("channel", memberJoinedChannelEvent.Channel),
|
||||
zap.Uint("incident_id", incidentEntity.ID))
|
||||
errors.AddErrors(fmt.Errorf("reporting team not found"))
|
||||
} else {
|
||||
reporterTeam = team
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
if len(errors.GetErrors()) > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
blocks := view.IncidentSummarySectionV3(
|
||||
incidentEntity, reportingTeamEntity, teamEntity, severityEntity, incidentStatus,
|
||||
incidentEntity, reporterTeam, responderTeam, severityEntity, incidentStatus,
|
||||
)
|
||||
msgOption := view.IncidentEphemeralMessage(incidentEntity, blocks)
|
||||
|
||||
_, err = mp.client.PostEphemeral(memberJoinedChannelEvent.Channel, memberJoinedChannelEvent.User, msgOption)
|
||||
_, err := mp.client.PostEphemeral(memberJoinedChannelEvent.Channel, memberJoinedChannelEvent.User, msgOption)
|
||||
if err != nil {
|
||||
logger.Error("post response failed", zap.Error(err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user