Skip to content

Commit

Permalink
chore: minor adds
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Jul 4, 2023
1 parent d90870f commit d39ae60
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
16 changes: 16 additions & 0 deletions homestar-runtime/src/event_handler/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum Event {
/// [Record]: libp2p::kad::Record
/// [Receipt]: homestar_core::workflow::Receipt
FindRecord(QueryRecord),
/// TODO
RemoveRecord(QueryRecord),
}

impl Event {
Expand All @@ -63,6 +65,7 @@ impl Event {
let _ = tx.send(());
}
Event::FindRecord(record) => record.find(event_handler),
Event::RemoveRecord(record) => record.remove(event_handler),
}
Ok(())
}
Expand Down Expand Up @@ -138,6 +141,8 @@ impl Captured {
.put_record(Record::new(wf_cid_bytes, wf_bytes), workflow_quorum)
.map_err(anyhow::Error::msg)?;

// TODO: Handle Workflow Complete / Num of Tasks finished.

Ok((receipt_cid, receipt_bytes.to_vec()))
} else {
Err(anyhow!("cannot convert receipt {receipt_cid} to bytes"))
Expand All @@ -162,6 +167,17 @@ impl QueryRecord {
.get_record(Key::new(&self.cid.to_bytes()));
event_handler.worker_swarm_senders.insert(id, self.sender);
}

fn remove<DB>(self, event_handler: &mut EventHandler<DB>)
where
DB: Database,
{
event_handler
.swarm
.behaviour_mut()
.kademlia
.remove_record(&Key::new(&self.cid.to_bytes()));
}
}

#[async_trait]
Expand Down
11 changes: 8 additions & 3 deletions homestar-runtime/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl Runner {

tokio::spawn({
let settings = settings.node().network().clone();
println!("Fuck");
WebSocketServer::start(settings, ws_tx.clone(), oneshot_sender.into())
});

Expand Down Expand Up @@ -247,10 +246,16 @@ mod test {
use super::*;
use homestar_core::test_utils;
use rand::thread_rng;
use std::time::Duration;
use std::{
sync::atomic::{AtomicUsize, Ordering},
time::Duration,
};

static ATOMIC_PORT: AtomicUsize = AtomicUsize::new(1338);

async fn setup() -> Runner {
let settings = Settings::load().unwrap();
let mut settings = Settings::load().unwrap();
settings.node.network.websocket_port = ATOMIC_PORT.fetch_add(1, Ordering::SeqCst) as u16;
let db = crate::test_utils::db::MemoryDb::setup_connection_pool(
Settings::load().unwrap().node(),
)
Expand Down
4 changes: 2 additions & 2 deletions homestar-runtime/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub struct Monitoring {
/// Application settings.
#[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct Settings {
monitoring: Monitoring,
node: Node,
pub(crate) monitoring: Monitoring,
pub(crate) node: Node,
}

impl Settings {
Expand Down

0 comments on commit d39ae60

Please sign in to comment.