Adding wfd config, endpoint to get state
This commit is contained in:
parent
eb590c848e
commit
f5ca3315f0
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"port": 2503
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
"type": "redis",
|
||||||
|
"url": "redis://localhost",
|
||||||
|
"prefix": "another"
|
||||||
|
},
|
||||||
|
"executor": {
|
||||||
|
"type": "local",
|
||||||
|
"workers": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+28
-13
@@ -3,7 +3,7 @@ use actix_web::{error, middleware::Logger, web, App, HttpResponse, HttpServer, R
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::{mpsc, oneshot};
|
||||||
use waterfall::prelude::*;
|
use waterfall::prelude::*;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@@ -90,24 +90,19 @@ struct SimpleError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_state(state: web::Data<AppState>) -> impl Responder {
|
async fn get_state(state: web::Data<AppState>) -> impl Responder {
|
||||||
// Build the current state
|
let (response, rx) = oneshot::channel();
|
||||||
// let (response, rx) = oneshot::channel();
|
|
||||||
|
|
||||||
/*
|
|
||||||
state
|
state
|
||||||
.config
|
.storage_tx
|
||||||
.tracker
|
.send(StorageMessage::LoadState { response })
|
||||||
.send(TrackerMessage::GetRun { run_id, response })
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match rx.await.unwrap() {
|
match rx.await {
|
||||||
Ok(run) => HttpResponse::Ok().json(run),
|
Ok(world) => HttpResponse::Ok().json(world),
|
||||||
Err(error) => HttpResponse::BadRequest().json(SimpleError {
|
Err(error) => HttpResponse::BadRequest().json(SimpleError {
|
||||||
error: format!("{:?}", error),
|
error: format!("{:?}", error),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
HttpResponse::Ok().body("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -152,8 +147,8 @@ struct Args {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct AppState {
|
struct AppState {
|
||||||
exe_tx: mpsc::UnboundedSender<ExecutorMessage>,
|
|
||||||
storage_tx: mpsc::UnboundedSender<StorageMessage>,
|
storage_tx: mpsc::UnboundedSender<StorageMessage>,
|
||||||
|
runner_tx: mpsc::UnboundedSender<RunnerMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
@@ -175,10 +170,28 @@ async fn main() -> std::io::Result<()> {
|
|||||||
// Start the workers
|
// Start the workers
|
||||||
let (exe_tx, exe_handle) = config.executor.start();
|
let (exe_tx, exe_handle) = config.executor.start();
|
||||||
let (storage_tx, storage_handle) = config.storage.start();
|
let (storage_tx, storage_handle) = config.storage.start();
|
||||||
|
let (runner_tx, runner_rx) = mpsc::unbounded_channel();
|
||||||
|
|
||||||
let data = web::Data::new(AppState {
|
let data = web::Data::new(AppState {
|
||||||
exe_tx: exe_tx.clone(),
|
|
||||||
storage_tx: storage_tx.clone(),
|
storage_tx: storage_tx.clone(),
|
||||||
|
runner_tx: runner_tx.clone(),
|
||||||
|
});
|
||||||
|
|
||||||
|
let tasks = world_def.taskset().unwrap();
|
||||||
|
let mut runner = Runner::new(
|
||||||
|
tasks,
|
||||||
|
world_def.variables,
|
||||||
|
runner_rx,
|
||||||
|
exe_tx.clone(),
|
||||||
|
storage_tx.clone(),
|
||||||
|
world_def.output_options,
|
||||||
|
args.force_recheck,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let runner_handle = tokio::spawn(async move {
|
||||||
|
runner.run().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||||
@@ -236,6 +249,8 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Shutdown the runner
|
// Shutdown the runner
|
||||||
|
runner_tx.send(RunnerMessage::Stop {}).unwrap();
|
||||||
|
runner_handle.await.unwrap();
|
||||||
exe_tx.send(ExecutorMessage::Stop {}).unwrap();
|
exe_tx.send(ExecutorMessage::Stop {}).unwrap();
|
||||||
exe_handle.await.unwrap();
|
exe_handle.await.unwrap();
|
||||||
storage_tx.send(StorageMessage::Stop {}).unwrap();
|
storage_tx.send(StorageMessage::Stop {}).unwrap();
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
pub use crate::calendar::Calendar;
|
pub use crate::calendar::Calendar;
|
||||||
pub use crate::executors::*;
|
pub use crate::executors::*;
|
||||||
pub use crate::runner::Runner;
|
pub use crate::runner::{Runner, RunnerMessage};
|
||||||
pub use crate::storage::*;
|
pub use crate::storage::*;
|
||||||
pub use crate::task::{TaskDefinition, TaskResources};
|
pub use crate::task::{TaskDefinition, TaskResources};
|
||||||
pub use crate::world::WorldDefinition;
|
pub use crate::world::WorldDefinition;
|
||||||
|
|||||||
Reference in New Issue
Block a user