Refactored engine
This commit is contained in:
@@ -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?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,14 +57,7 @@ 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 (child, manifest) = get_manifest(
|
||||
@@ -78,10 +71,6 @@ impl StrategyEngine {
|
||||
strategy.child.kill().await?;
|
||||
strategy.child = child;
|
||||
strategy.manifest = manifest;
|
||||
}
|
||||
|
||||
let engine = self.clone();
|
||||
tokio::spawn(async move { engine.run().await });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+1
-2
@@ -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??;
|
||||
|
||||
Reference in New Issue
Block a user