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
@@ -12,7 +12,11 @@ static EXPIRE_CONSTANT: u64 = 30;
// Otherwise, commit to database after 5 seconds.
static SAVE_CONSTANT: u64 = 5;
type Message = (String, String, bool);
struct Message {
channel: String,
id: String,
is_dm: bool
}
#[derive(Debug)]
struct Task {
@@ -27,7 +31,7 @@ lazy_static! {
}
pub async fn queue(channel: String, id: String, is_dm: bool) {
CHANNEL.0.send((channel, id, is_dm)).await.ok();
CHANNEL.0.send(Message { channel, id, is_dm }).await.ok();
}
pub async fn run() {
@@ -68,7 +72,7 @@ pub async fn run() {
keys.clear();
// Queue incoming tasks.
while let Ok((channel, id, is_dm)) = CHANNEL.1.try_recv() {
while let Ok(Message { channel, id, is_dm }) = CHANNEL.1.try_recv() {
if let Some(mut existing_task) = tasks.get_mut(&channel) {
existing_task.id = id;
existing_task.last_updated = Instant::now();