fix: panic on launch
Now we start the admin and sending threads at a later time.
This commit is contained in:
parent
50b0eb9929
commit
8b5b7a1f63
20 changed files with 46 additions and 53 deletions
|
@ -8,7 +8,7 @@ use ruma::{
|
|||
RoomId, UserId,
|
||||
};
|
||||
|
||||
use std::{collections::HashMap};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::Result;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ use ruma::{
|
|||
EventId, RoomAliasId, RoomId, RoomName, RoomVersionId, ServerName, UserId,
|
||||
};
|
||||
use serde_json::value::to_raw_value;
|
||||
use tokio::sync::{mpsc, MutexGuard};
|
||||
use tokio::sync::{mpsc, Mutex, MutexGuard};
|
||||
|
||||
use crate::{
|
||||
api::client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
|
||||
|
@ -164,25 +164,29 @@ pub enum AdminRoomEvent {
|
|||
SendMessage(RoomMessageEventContent),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Service {
|
||||
pub sender: mpsc::UnboundedSender<AdminRoomEvent>,
|
||||
receiver: Mutex<mpsc::UnboundedReceiver<AdminRoomEvent>>,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
pub fn build() -> Arc<Self> {
|
||||
let (sender, receiver) = mpsc::unbounded_channel();
|
||||
let self1 = Arc::new(Self { sender });
|
||||
let self2 = Arc::clone(&self1);
|
||||
|
||||
tokio::spawn(async move {
|
||||
self2.start_handler(receiver).await;
|
||||
});
|
||||
|
||||
self1
|
||||
Arc::new(Self {
|
||||
sender,
|
||||
receiver: Mutex::new(receiver),
|
||||
})
|
||||
}
|
||||
|
||||
async fn start_handler(&self, mut receiver: mpsc::UnboundedReceiver<AdminRoomEvent>) {
|
||||
pub fn start_handler(self: &Arc<Self>) {
|
||||
let self2 = Arc::clone(&self);
|
||||
tokio::spawn(async move {
|
||||
self2.handler().await;
|
||||
});
|
||||
}
|
||||
|
||||
async fn handler(&self) {
|
||||
let mut receiver = self.receiver.lock().await;
|
||||
// TODO: Use futures when we have long admin commands
|
||||
//let mut futures = FuturesUnordered::new();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
|
||||
use crate::Result;
|
||||
|
|
|
@ -7,7 +7,7 @@ use ruma::{
|
|||
serde::Raw,
|
||||
RoomId, UserId,
|
||||
};
|
||||
use std::{collections::BTreeMap};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub struct Service {
|
||||
pub db: &'static dyn Data,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
|
||||
use crate::Result;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
use ruma::RoomId;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod data;
|
||||
use std::{collections::HashMap};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub use data::Data;
|
||||
use ruma::{events::presence::PresenceEvent, RoomId, UserId};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
|
||||
use crate::Result;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
use ruma::{events::SyncEphemeralRoomEvent, RoomId, UserId};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mod data;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
sync::{Mutex},
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
pub use data::Data;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
use ruma::RoomId;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
use ruma::{signatures::CanonicalJsonObject, EventId};
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
|
||||
use crate::Result;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
use ruma::{RoomId, UserId};
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::{
|
|||
use crate::{
|
||||
api::{appservice_server, server_server},
|
||||
services,
|
||||
utils::{calculate_hash},
|
||||
utils::calculate_hash,
|
||||
Config, Error, PduEvent, Result,
|
||||
};
|
||||
use federation::transactions::send_transaction_message;
|
||||
|
@ -37,7 +37,7 @@ use ruma::{
|
|||
};
|
||||
use tokio::{
|
||||
select,
|
||||
sync::{mpsc, Semaphore},
|
||||
sync::{mpsc, Mutex, Semaphore},
|
||||
};
|
||||
use tracing::{error, warn};
|
||||
|
||||
|
@ -88,6 +88,7 @@ pub struct Service {
|
|||
/// The state for a given state hash.
|
||||
pub(super) maximum_requests: Arc<Semaphore>,
|
||||
pub sender: mpsc::UnboundedSender<(OutgoingKind, SendingEventType, Vec<u8>)>,
|
||||
receiver: Mutex<mpsc::UnboundedReceiver<(OutgoingKind, SendingEventType, Vec<u8>)>>,
|
||||
}
|
||||
|
||||
enum TransactionStatus {
|
||||
|
@ -99,25 +100,24 @@ enum TransactionStatus {
|
|||
impl Service {
|
||||
pub fn build(db: &'static dyn Data, config: &Config) -> Arc<Self> {
|
||||
let (sender, receiver) = mpsc::unbounded_channel();
|
||||
|
||||
let self1 = Arc::new(Self {
|
||||
Arc::new(Self {
|
||||
db,
|
||||
sender,
|
||||
receiver: Mutex::new(receiver),
|
||||
maximum_requests: Arc::new(Semaphore::new(config.max_concurrent_requests as usize)),
|
||||
});
|
||||
let self2 = Arc::clone(&self1);
|
||||
|
||||
tokio::spawn(async move {
|
||||
self2.start_handler(receiver).await.unwrap();
|
||||
});
|
||||
|
||||
self1
|
||||
})
|
||||
}
|
||||
|
||||
async fn start_handler(
|
||||
&self,
|
||||
mut receiver: mpsc::UnboundedReceiver<(OutgoingKind, SendingEventType, Vec<u8>)>,
|
||||
) -> Result<()> {
|
||||
pub fn start_handler(self: &Arc<Self>) {
|
||||
let self2 = Arc::clone(&self);
|
||||
tokio::spawn(async move {
|
||||
self2.handler().await.unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
async fn handler(&self) -> Result<()> {
|
||||
let mut receiver = self.receiver.lock().await;
|
||||
|
||||
let mut futures = FuturesUnordered::new();
|
||||
|
||||
let mut current_transaction_status = HashMap::<OutgoingKind, TransactionStatus>::new();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
|
||||
use crate::Result;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod data;
|
||||
|
||||
|
||||
pub use data::Data;
|
||||
|
||||
use ruma::{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue