1 parent
131f1ec84a
commit
b40985528e
1 file changed
+8
-8
@@ -1,5 +1,5 @@
|
|||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
@@ -13,7 +13,7 @@ const MAX_EVENT_ARGUMENTS: usize = 200;
|
|||||||
|
|
||||||
/// Lifecycle event of a job, broadcast globally.
|
/// Lifecycle event of a job, broadcast globally.
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum JobEvent {
|
pub enum JobEvent {
|
||||||
Queued {
|
Queued {
|
||||||
id: u64,
|
id: u64,
|
||||||
@@ -46,7 +46,7 @@ pub enum JobEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum Progress {
|
pub enum Progress {
|
||||||
ToolCall {
|
ToolCall {
|
||||||
iteration: usize,
|
iteration: usize,
|
||||||
@@ -98,7 +98,7 @@ pub struct JobSubscription {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventBus {
|
pub struct EventBus {
|
||||||
lifecycle: broadcast::Sender<JobEvent>,
|
lifecycle: broadcast::Sender<JobEvent>,
|
||||||
jobs: Arc<RwLock<HashMap<u64, Arc<JobChannel>>>>,
|
jobs: Arc<Mutex<HashMap<u64, Arc<JobChannel>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventBus {
|
impl EventBus {
|
||||||
@@ -107,7 +107,7 @@ impl EventBus {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
lifecycle,
|
lifecycle,
|
||||||
jobs: Arc::new(RwLock::new(HashMap::new())),
|
jobs: Arc::new(Mutex::new(HashMap::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ impl EventBus {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.jobs
|
self.jobs
|
||||||
.write()
|
.lock()
|
||||||
.expect("job registry lock poisoned")
|
.expect("job registry lock poisoned")
|
||||||
.insert(id, channel.clone());
|
.insert(id, channel.clone());
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ impl EventBus {
|
|||||||
|
|
||||||
if let Some(channel) = self
|
if let Some(channel) = self
|
||||||
.jobs
|
.jobs
|
||||||
.write()
|
.lock()
|
||||||
.expect("job registry lock poisoned")
|
.expect("job registry lock poisoned")
|
||||||
.remove(&id)
|
.remove(&id)
|
||||||
{
|
{
|
||||||
@@ -181,7 +181,7 @@ impl EventBus {
|
|||||||
pub fn subscribe_job(&self, id: u64) -> Option<JobSubscription> {
|
pub fn subscribe_job(&self, id: u64) -> Option<JobSubscription> {
|
||||||
let channel = self
|
let channel = self
|
||||||
.jobs
|
.jobs
|
||||||
.read()
|
.lock()
|
||||||
.expect("job registry lock poisoned")
|
.expect("job registry lock poisoned")
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.cloned()?;
|
.cloned()?;
|
||||||
|
|||||||
Reference in new issue
Block a user