mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 14:05:52 +01:00
(refs #74)Web hook request is sent asynchronously.
This commit is contained in:
@@ -4,10 +4,13 @@ import scala.slick.driver.H2Driver.simple._
|
|||||||
import Database.threadLocalSession
|
import Database.threadLocalSession
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
trait WebHookService {
|
trait WebHookService {
|
||||||
import WebHookService._
|
import WebHookService._
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(classOf[WebHookService])
|
||||||
|
|
||||||
def getWebHookURLs(owner: String, repository: String): List[WebHook] =
|
def getWebHookURLs(owner: String, repository: String): List[WebHook] =
|
||||||
Query(WebHooks).filter(_.byRepository(owner, repository)).sortBy(_.url).list
|
Query(WebHooks).filter(_.byRepository(owner, repository)).sortBy(_.url).list
|
||||||
|
|
||||||
@@ -23,6 +26,7 @@ trait WebHookService {
|
|||||||
import org.json4s.jackson.Serialization.{read, write}
|
import org.json4s.jackson.Serialization.{read, write}
|
||||||
import org.apache.http.client.methods.HttpPost
|
import org.apache.http.client.methods.HttpPost
|
||||||
import org.apache.http.impl.client.DefaultHttpClient
|
import org.apache.http.impl.client.DefaultHttpClient
|
||||||
|
import scala.concurrent._
|
||||||
|
|
||||||
implicit val formats = Serialization.formats(NoTypeHints)
|
implicit val formats = Serialization.formats(NoTypeHints)
|
||||||
|
|
||||||
@@ -33,11 +37,19 @@ trait WebHookService {
|
|||||||
val httpClient = new DefaultHttpClient()
|
val httpClient = new DefaultHttpClient()
|
||||||
|
|
||||||
webHookURLs.foreach { webHookUrl =>
|
webHookURLs.foreach { webHookUrl =>
|
||||||
|
val f = future {
|
||||||
val httpPost = new HttpPost(webHookUrl.url)
|
val httpPost = new HttpPost(webHookUrl.url)
|
||||||
httpPost.getParams.setParameter("payload", json)
|
httpPost.getParams.setParameter("payload", json)
|
||||||
httpClient.execute(httpPost)
|
httpClient.execute(httpPost)
|
||||||
httpPost.releaseConnection()
|
httpPost.releaseConnection()
|
||||||
}
|
}
|
||||||
|
f.onSuccess {
|
||||||
|
case s => logger.debug(s"Success: web hook request to ${webHookUrl.url}")
|
||||||
|
}
|
||||||
|
f.onFailure {
|
||||||
|
case t => logger.error(s"Failed: web hook request to ${webHookUrl.url}", t)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user