diff options
author | Chris <ccbrown112@gmail.com> | 2017-10-03 10:53:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-03 10:53:53 -0500 |
commit | 5e69ce099f521aa49fc267c62235c003eae530ff (patch) | |
tree | c7177e4cac419082753225819f62d07c8b5671e8 /app/webhook.go | |
parent | bfe7955fb0c72bb6f3e0a1e0aaca70cff27d7ddc (diff) | |
download | chat-5e69ce099f521aa49fc267c62235c003eae530ff.tar.gz chat-5e69ce099f521aa49fc267c62235c003eae530ff.tar.bz2 chat-5e69ce099f521aa49fc267c62235c003eae530ff.zip |
Goroutine wranglin (#7556)
* goroutine wranglin
* synchronize WebConn.WritePump
Diffstat (limited to 'app/webhook.go')
-rw-r--r-- | app/webhook.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/app/webhook.go b/app/webhook.go index 9531cba10..9d9b24b10 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -79,7 +79,11 @@ func (a *App) handleWebhookEvents(post *model.Post, team *model.Team, channel *m TriggerWord: triggerWord, FileIds: strings.Join(post.FileIds, ","), } - go a.TriggerWebhook(payload, hook, post, channel) + a.Go(func(hook *model.OutgoingWebhook) func() { + return func() { + a.TriggerWebhook(payload, hook, post, channel) + } + }(hook)) } return nil @@ -97,23 +101,25 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model. } for _, url := range hook.CallbackURLs { - go func(url string) { - req, _ := http.NewRequest("POST", url, body) - req.Header.Set("Content-Type", contentType) - req.Header.Set("Accept", "application/json") - if resp, err := utils.HttpClient(false).Do(req); err != nil { - l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.event_post.error"), err.Error()) - } else { - defer CloseBody(resp) - webhookResp := model.OutgoingWebhookResponseFromJson(resp.Body) + a.Go(func(url string) func() { + return func() { + req, _ := http.NewRequest("POST", url, body) + req.Header.Set("Content-Type", contentType) + req.Header.Set("Accept", "application/json") + if resp, err := utils.HttpClient(false).Do(req); err != nil { + l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.event_post.error"), err.Error()) + } else { + defer CloseBody(resp) + webhookResp := model.OutgoingWebhookResponseFromJson(resp.Body) - if webhookResp != nil && webhookResp.Text != nil { - if _, err := a.CreateWebhookPost(hook.CreatorId, channel, *webhookResp.Text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type); err != nil { - l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.create_post.error"), err) + if webhookResp != nil && webhookResp.Text != nil { + if _, err := a.CreateWebhookPost(hook.CreatorId, channel, *webhookResp.Text, webhookResp.Username, webhookResp.IconURL, webhookResp.Props, webhookResp.Type); err != nil { + l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.create_post.error"), err) + } } } } - }(url) + }(url)) } } |