feat(task_queue): ack task

closes #111 and closes #86
This commit is contained in:
Paul
2021-11-02 13:30:36 +00:00
parent 0025bea23d
commit 012a30ce61
7 changed files with 178 additions and 76 deletions
+7 -3
View File
@@ -4,20 +4,24 @@ use mongodb::bson::{doc, to_bson};
use crate::{database::*, notifications::events::ClientboundNotification};
type Message = (String, String, String);
struct Message {
channel: String,
id: String,
content: String
}
lazy_static! {
static ref CHANNEL: (Sender<Message>, Receiver<Message>) = bounded(100);
}
pub async fn queue(channel: String, id: String, content: String) {
CHANNEL.0.send((channel, id, content)).await.ok();
CHANNEL.0.send(Message { channel, id, content }).await.ok();
}
pub async fn run() {
let messages = get_collection("messages");
while let Ok((channel, id, content)) = CHANNEL.1.recv().await {
while let Ok(Message { channel, id, content }) = CHANNEL.1.recv().await {
if let Ok(embeds) = Embed::generate(content).await {
if let Ok(bson) = to_bson(&embeds) {
if let Ok(_) = messages