This commit is contained in:
2026-03-19 01:14:46 +01:00
parent 506d4eb111
commit a51c4258c2
13 changed files with 223 additions and 52 deletions
+21 -2
View File
@@ -1,14 +1,17 @@
use std::num::NonZeroU64;
use async_nats::Client;
use async_trait::async_trait;
use postcard::{from_bytes, to_stdvec};
use types::{
error::{CorroError, CorroErrorType},
jobs::{JobResponse, JobsMap, JobsResponseMap},
jobs::{JobResponse, JobsMap, JobsResponseMap, TriggerMaster},
};
#[async_trait]
pub trait JobClient {
async fn send_job(&self, job: JobsMap) -> Result<JobsResponseMap, CorroError>;
async fn trigger_master(&self, id: NonZeroU64) -> Result<(), CorroError>;
}
#[async_trait]
@@ -22,7 +25,7 @@ impl JobClient for Client {
match self
.request(
format!("corro-dj.{subject}"),
format!("corro-dj.job.{subject}"),
to_stdvec(&job).unwrap().into(),
)
.await
@@ -47,4 +50,20 @@ impl JobClient for Client {
}),
}
}
async fn trigger_master(&self, id: NonZeroU64) -> Result<(), CorroError> {
match self
.request(
format!("corro-dj.queue.{id}"),
to_stdvec(&TriggerMaster { guild_id: id }).unwrap().into(),
)
.await
{
Ok(_) => Ok(()),
Err(why) => Err(CorroError {
error_type: CorroErrorType::NatsError,
message: why.to_string(),
}),
}
}
}
+11
View File
@@ -16,6 +16,7 @@ fn get_key(id: NonZeroU64) -> String {
pub trait KVClient {
async fn get_queue(&self, id: NonZeroU64) -> Result<Queue, CorroError>;
async fn set_queue(&self, id: NonZeroU64, queue: &Queue) -> Result<u64, CorroError>;
async fn delete_queue(&self, id: NonZeroU64) -> Result<(), CorroError>;
}
#[async_trait]
@@ -51,4 +52,14 @@ impl KVClient for Store {
}),
}
}
async fn delete_queue(&self, id: NonZeroU64) -> Result<(), CorroError> {
match self.delete(get_key(id)).await {
Ok(_) => Ok(()),
Err(why) => Err(CorroError {
error_type: CorroErrorType::KVError,
message: why.to_string(),
}),
}
}
}