Process events on a separate thread
GitLab really wants you to respond in 10 seconds, and if we're doing a bit of work (e.g. sending more than one matrix message per event), then we can easily blow through that.
This commit is contained in:
parent
eb5bdc3fd5
commit
33d3313927
16
src/main.rs
16
src/main.rs
@ -20,6 +20,7 @@ use matrix_sdk::{
|
||||
ruma::{events::room::message::RoomMessageEventContent, OwnedRoomOrAliasId},
|
||||
BaseRoom, Client,
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
use warp::Filter;
|
||||
|
||||
use crate::event::{MergeRequestAction, PipelineStatus};
|
||||
@ -167,6 +168,15 @@ async fn run() -> anyhow::Result<()> {
|
||||
|
||||
let matrix_client = matrix_connect(&config).await.context("Failed to connect to Matrix")?;
|
||||
|
||||
let (event_tx, mut event_rx) = mpsc::channel::<(GitlabEvent, OwnedRoomOrAliasId)>(100);
|
||||
tokio::spawn(async move {
|
||||
while let Some((event, room)) = event_rx.recv().await {
|
||||
if let Err(err) = handle_gitlab_event(event, &room, &matrix_client).await {
|
||||
warn!("Failed to handle payload: {}", err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let gitlab_root_path = if let Some(url_prefix) = config.url_prefix.as_ref() {
|
||||
url_prefix.split('/').fold(warp::any().boxed(), |last, segment| {
|
||||
if segment.is_empty() {
|
||||
@ -186,7 +196,7 @@ async fn run() -> anyhow::Result<()> {
|
||||
.and(warp::body::json())
|
||||
.then(move |token: String, event: event::GitlabEvent| {
|
||||
let config = Arc::clone(&config);
|
||||
let matrix_client = matrix_client.clone();
|
||||
let event_tx = event_tx.clone();
|
||||
|
||||
async move {
|
||||
let project = event.project();
|
||||
@ -198,8 +208,8 @@ async fn run() -> anyhow::Result<()> {
|
||||
} else {
|
||||
debug!("payload: {:?}", event);
|
||||
if let Some(room) = repo_config.room.as_ref().or(config.default_room.as_ref()) {
|
||||
if let Err(err) = handle_gitlab_event(event, &room, &matrix_client).await {
|
||||
warn!("Failed to handle payload: {}", err);
|
||||
if let Err(err) = event_tx.send((event, room.clone())).await {
|
||||
warn!("Failed to enqueue payload: {}", err);
|
||||
}
|
||||
warp::reply::with_status("OK", StatusCode::OK)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user