Multi-thread rocket and hive

This commit is contained in:
Martin Loffler
2021-04-30 13:19:31 +02:00
parent f163cb65de
commit 33b0658680
3 changed files with 26 additions and 20 deletions

View File

@@ -38,7 +38,7 @@ pub enum Presence {
Online, Online,
Idle, Idle,
Busy, Busy,
Invisible Invisible,
} }
#[derive(Validate, Serialize, Deserialize, Debug)] #[derive(Validate, Serialize, Deserialize, Debug)]
@@ -47,7 +47,7 @@ pub struct UserStatus {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
text: Option<String>, text: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
presence: Option<Presence> presence: Option<Presence>,
} }
#[derive(Validate, Serialize, Deserialize, Debug)] #[derive(Validate, Serialize, Deserialize, Debug)]

View File

@@ -1,8 +1,8 @@
use crate::database::get_collection; use crate::database::get_collection;
use log::info; use log::info;
use serde::{Deserialize, Serialize};
use mongodb::bson::{doc, from_document}; use mongodb::bson::{doc, from_document};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct MigrationInfo { struct MigrationInfo {
@@ -59,21 +59,23 @@ pub async fn run_migrations(revision: i32) -> i32 {
let messages = get_collection("messages"); let messages = get_collection("messages");
let attachments = get_collection("attachments"); let attachments = get_collection("attachments");
messages.update_many( messages
doc! { "attachment": { "$exists": 1 } }, .update_many(
doc! { "$set": { "attachment.tag": "attachments", "attachment.size": 0 } }, doc! { "attachment": { "$exists": 1 } },
None doc! { "$set": { "attachment.tag": "attachments", "attachment.size": 0 } },
) None,
.await )
.expect("Failed to update messages."); .await
.expect("Failed to update messages.");
attachments.update_many( attachments
doc! { }, .update_many(
doc! { "$set": { "tag": "attachments", "size": 0 } }, doc! {},
None doc! { "$set": { "tag": "attachments", "size": 0 } },
) None,
.await )
.expect("Failed to update attachments."); .await
.expect("Failed to update attachments.");
} }
// Reminder to update LATEST_REVISION when adding new migrations. // Reminder to update LATEST_REVISION when adding new migrations.

View File

@@ -18,6 +18,7 @@ pub mod notifications;
pub mod routes; pub mod routes;
pub mod util; pub mod util;
use async_std::task;
use chrono::Duration; use chrono::Duration;
use futures::join; use futures::join;
use log::info; use log::info;
@@ -50,10 +51,13 @@ async fn main() {
}) })
.expect("Error setting Ctrl-C handler"); .expect("Error setting Ctrl-C handler");
let web_task = task::spawn(launch_web());
let hive_task = task::spawn(notifications::hive::listen());
join!( join!(
launch_web(), web_task,
notifications::websocket::launch_server(), hive_task,
notifications::hive::listen(), notifications::websocket::launch_server()
); );
} }