@@ -14,8 +14,6 @@ use tracing_subscriber::EnvFilter;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
// let output_file = std::fs::File::create("target/nocontrol.log")?;
|
|
||||||
|
|
||||||
let cancellation_parent = CancellationToken::new();
|
let cancellation_parent = CancellationToken::new();
|
||||||
let cancellation = cancellation_parent.child_token();
|
let cancellation = cancellation_parent.child_token();
|
||||||
|
|
||||||
@@ -34,7 +32,6 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.add_directive("sqlx=warn".parse().unwrap())
|
.add_directive("sqlx=warn".parse().unwrap())
|
||||||
.add_directive("debug".parse().unwrap()),
|
.add_directive("debug".parse().unwrap()),
|
||||||
)
|
)
|
||||||
// .with_writer(output_file)
|
|
||||||
.with_file(false)
|
.with_file(false)
|
||||||
.with_line_number(false)
|
.with_line_number(false)
|
||||||
.with_target(false)
|
.with_target(false)
|
||||||
@@ -43,11 +40,6 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let database_url = "postgres://devuser:devpassword@localhost:5432/dev";
|
let database_url = "postgres://devuser:devpassword@localhost:5432/dev";
|
||||||
|
|
||||||
// 1. Start up worker planes
|
|
||||||
// start_worker(database_url).await?;
|
|
||||||
// start_worker(database_url).await?;
|
|
||||||
// start_worker(database_url).await?;
|
|
||||||
|
|
||||||
let process_manager = ProcessManager::new();
|
let process_manager = ProcessManager::new();
|
||||||
let operator = OperatorState::new(ProcessOperator::new(process_manager));
|
let operator = OperatorState::new(ProcessOperator::new(process_manager));
|
||||||
let control_plane =
|
let control_plane =
|
||||||
@@ -65,79 +57,25 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Spawn a task that toggles the desired state periodically
|
// Spawn control plane
|
||||||
// tokio::spawn({
|
tokio::spawn({
|
||||||
// let control_plane = control_plane.clone();
|
let control_plane = control_plane.clone();
|
||||||
// async move {
|
async move {
|
||||||
// let mut running = true;
|
let _ = control_plane.execute().await;
|
||||||
// loop {
|
}
|
||||||
// tokio::time::sleep(Duration::from_secs(10)).await;
|
});
|
||||||
|
|
||||||
// running = !running;
|
// Run TUI
|
||||||
// let desired_state = if running {
|
nocontrol_tui::run(control_plane).await?;
|
||||||
// DesiredProcessState::Running
|
|
||||||
// } else {
|
|
||||||
// DesiredProcessState::Stopped
|
|
||||||
// };
|
|
||||||
|
|
||||||
// tracing::info!("Toggling worker-process to {:?}", desired_state);
|
|
||||||
|
|
||||||
// let _ = control_plane
|
|
||||||
// .add_manifest(Manifest {
|
|
||||||
// name: "worker-process".into(),
|
|
||||||
// metadata: ManifestMetadata {},
|
|
||||||
// spec: Specifications::Process(ProcessManifest {
|
|
||||||
// name: "data-worker".into(),
|
|
||||||
// desired_state,
|
|
||||||
// }),
|
|
||||||
// })
|
|
||||||
// .await;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // Spawn control plane
|
|
||||||
// tokio::spawn({
|
|
||||||
// let control_plane = control_plane.clone();
|
|
||||||
// async move {
|
|
||||||
// let _ = control_plane.execute().await;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
control_plane
|
|
||||||
.execute_with_cancellation(cancellation)
|
|
||||||
.await?;
|
|
||||||
// // Run TUI
|
|
||||||
// nocontrol_tui::run(control_plane).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// async fn start_worker(database_url: &str) -> anyhow::Result<()> {
|
|
||||||
// let database_url = database_url.to_string();
|
|
||||||
// tokio::spawn(async move {
|
|
||||||
// let process_manager = ProcessManager::new();
|
|
||||||
// let operator = OperatorState::new(ProcessOperator::new(process_manager));
|
|
||||||
// let control_plane = nocontrol::ControlPlane::new(
|
|
||||||
// operator,
|
|
||||||
// BackingStore::postgres(&database_url)
|
|
||||||
// .await
|
|
||||||
// .expect("to be able to connect to database"),
|
|
||||||
// );
|
|
||||||
|
|
||||||
// control_plane
|
|
||||||
// .execute()
|
|
||||||
// .await
|
|
||||||
// .expect("control plane crashed");
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// The operator that manages processes via noprocess
|
// The operator that manages processes via noprocess
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ProcessOperator {
|
pub struct ProcessOperator {
|
||||||
process_manager: ProcessManager,
|
process_manager: ProcessManager,
|
||||||
|
|
||||||
// Maps manifest name -> process handle ID in the ProcessManager
|
// Maps manifest name -> process handle ID in the ProcessManager
|
||||||
process_ids: Arc<RwLock<HashMap<String, HandleID>>>,
|
process_ids: Arc<RwLock<HashMap<String, HandleID>>>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user