Refactored engine

This commit is contained in:
2026-07-31 01:42:45 +02:00
parent b5a1a07cf0
commit f3e2deab09
5 changed files with 25 additions and 25 deletions
+14 -2
View File
@@ -1,11 +1,11 @@
pub mod command;
pub mod execution;
pub mod strategy;
pub mod terminal;
use crate::{
engine::strategy::StrategyEngine,
engine::{strategy::StrategyEngine, terminal::TerminalServer},
store::{accounts::AccountList, config::Config},
terminal::TerminalServer,
};
use hypersdk::hypercore::ws::ConnectionStream;
use pulse_sdk::prelude::*;
@@ -56,4 +56,16 @@ impl Engine {
signals: Arc::new(Mutex::new(Vec::new())),
}))
}
/// Starts the main strategy server
/// When a strategy is reloaded it restarts automatically
pub async fn run(&self) -> anyhow::Result<()> {
loop {
self.strategy_engine.run().await?;
self.terminal_server
.info("engine::main", "Strategy stopped, restarting")
.await?;
}
}
}
+10 -21
View File
@@ -57,31 +57,20 @@ impl StrategyEngine {
self.strategy.lock().await.send(msg).await
}
pub async fn spawn(self: &Arc<Self>) {
let engine = self.clone();
tokio::spawn(async move { engine.run().await });
}
pub async fn reload(self: &Arc<Self>, id: &str) -> tokio::io::Result<()> {
{
let strategy = pulse_strategy(id)?;
let strategy = pulse_strategy(id)?;
let (child, manifest) = get_manifest(
&strategy,
&strategy.join("strategy.bash"),
&fs::read(strategy.join("strategy.toml")).await?,
)?;
let (child, manifest) = get_manifest(
&strategy,
&strategy.join("strategy.bash"),
&fs::read(strategy.join("strategy.toml")).await?,
)?;
let mut strategy = self.strategy.lock().await;
let mut strategy = self.strategy.lock().await;
strategy.child.kill().await?;
strategy.child = child;
strategy.manifest = manifest;
}
let engine = self.clone();
tokio::spawn(async move { engine.run().await });
strategy.child.kill().await?;
strategy.child = child;
strategy.manifest = manifest;
Ok(())
}
+1 -2
View File
@@ -1,7 +1,6 @@
pub mod engine;
pub mod fetch;
pub mod store;
pub mod terminal;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
@@ -10,7 +9,7 @@ async fn main() -> anyhow::Result<()> {
let server = engine.terminal_server.spawn_server().await;
let broadcaster = engine.terminal_server.spawn_broadcaster().await;
engine.strategy_engine.spawn().await;
engine.run().await?;
server.await??;
broadcaster.await??;