fix: lets create the agent async
so that we don't timeout any webhooks from git
@@ -127,6 +127,8 @@ func (s *Server) handlePullRequestCommentEvent(l *logrus.Entry, pc scm.PullReque
}
func (s *Server) handleGenericComment(l *logrus.Entry, ce *scmprovider.GenericCommentEvent) {
+ // lets invoke the agent creation async as this can take a little while
+ go func() {
agent, err := s.CreateAgent(l, ce.Repo.Namespace, ce.Repo.Name, ce.HeadSha)
if err != nil {
agent.Logger.WithError(err).Error("Error creating agent for GenericCommentEvent.")
@@ -138,6 +140,7 @@ func (s *Server) handleGenericComment(l *logrus.Entry, ce *scmprovider.GenericCo
ce.Number,
)
s.handleGenericCommentWithAgent(l, ce, agent)
+ }()
}
func (s *Server) handleGenericCommentWithAgent(l *logrus.Entry, ce *scmprovider.GenericCommentEvent, agent plugins.Agent) {
@@ -179,6 +182,9 @@ func (s *Server) handlePushEvent(l *logrus.Entry, pe *scm.PushHook) {
"head": pe.After,
})
l.Info("Push event.")
+
+ // lets invoke the agent creation async as this can take a little while
+ go func() {
c := 0
ref := pe.After
if ref == "" {
@@ -202,6 +208,7 @@ func (s *Server) handlePushEvent(l *logrus.Entry, pe *scm.PushHook) {
}
}
l.WithField("count", strconv.Itoa(c)).Info("number of push handlers")
+ }()
}
func (s *Server) handlePullRequestEvent(l *logrus.Entry, pr *scm.PullRequestHook) {
@@ -214,6 +221,9 @@ func (s *Server) handlePullRequestEvent(l *logrus.Entry, pr *scm.PullRequestHook
})
action := pr.Action
l.Infof("Pull request %s.", action)
+
+ // lets invoke the agent creation async as this can take a little while
+ go func() {
c := 0
repo := pr.PullRequest.Base.Repo
if repo.Name == "" {
@@ -269,6 +279,7 @@ func (s *Server) handlePullRequestEvent(l *logrus.Entry, pr *scm.PullRequestHook
},
agent,
)
+ }()
}
// handleBranchEvent handles a branch event
@@ -287,6 +298,9 @@ func (s *Server) handleReviewEvent(l *logrus.Entry, re scm.ReviewHook) {
"url": re.Review.Link,
})
l.Infof("Review %s.", re.Action)
+
+ // lets invoke the agent creation async as this can take a little while
+ go func() {
repo := re.PullRequest.Base.Repo
agent, err := s.CreateAgent(l, repo.Namespace, repo.Name, re.PullRequest.Sha)
if err != nil {
@@ -334,6 +348,7 @@ func (s *Server) handleReviewEvent(l *logrus.Entry, re scm.ReviewHook) {
},
agent,
)
+ }()
}
func (s *Server) reportErrorToPullRequest(l *logrus.Entry, agent plugins.Agent, repo scm.Repository, pr *scm.PullRequestHook, err error) {
