queue worker task

This commit is contained in:
nora 2022-03-05 18:10:04 +01:00
parent f860714b2b
commit 800ccae604
8 changed files with 111 additions and 36 deletions

View file

@ -14,14 +14,24 @@ use crate::{
};
use connection::{ChannelId, ConnectionId};
use parking_lot::Mutex;
use std::{collections::HashMap, sync::Arc};
use std::{
collections::HashMap,
fmt::{Debug, Formatter},
sync::Arc,
};
use uuid::Uuid;
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct GlobalData {
inner: Arc<Mutex<GlobalDataInner>>,
}
impl Debug for GlobalData {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("[global data]")
}
}
impl Default for GlobalData {
fn default() -> Self {
Self {

View file

@ -14,7 +14,7 @@ macro_rules! newtype_id {
impl ::std::fmt::Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
self.0.fmt(f)
::std::fmt::Display::fmt(&self.0, f)
}
}

View file

@ -7,10 +7,18 @@ use parking_lot::Mutex;
use std::{
borrow::Borrow,
collections::HashMap,
fmt::{Debug, Display, Formatter},
sync::{atomic::AtomicUsize, Arc},
};
use tokio::sync::mpsc;
pub type Queue = Arc<RawQueue>;
pub type Queue = Arc<QueueInner>;
#[derive(Debug)]
pub enum QueueEvent {}
pub type QueueEventSender = mpsc::Sender<QueueEvent>;
pub type QueueEventReceiver = mpsc::Receiver<QueueEvent>;
newtype_id!(pub QueueId);
@ -26,8 +34,14 @@ impl Borrow<str> for QueueName {
}
}
impl Display for QueueName {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
#[derive(Debug)]
pub struct RawQueue {
pub struct QueueInner {
pub id: QueueId,
pub name: QueueName,
pub messages: Mutex<Vec<Message>>, // use a concurrent linked list???
@ -38,6 +52,7 @@ pub struct RawQueue {
/// If auto-delete is enabled, it keeps track of the consumer count.
pub deletion: QueueDeletion,
pub consumers: Mutex<HashMap<ConsumerId, Consumer>>,
pub event_send: QueueEventSender,
}
#[derive(Debug)]