@@ -14,8 +14,6 @@ use tracing_subscriber::EnvFilter;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
// let output_file = std::fs::File::create("target/nocontrol.log")?;
|
||||
|
||||
let cancellation_parent = CancellationToken::new();
|
||||
let cancellation = cancellation_parent.child_token();
|
||||
|
||||
@@ -34,7 +32,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
.add_directive("sqlx=warn".parse().unwrap())
|
||||
.add_directive("debug".parse().unwrap()),
|
||||
)
|
||||
// .with_writer(output_file)
|
||||
.with_file(false)
|
||||
.with_line_number(false)
|
||||
.with_target(false)
|
||||
@@ -43,11 +40,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
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 operator = OperatorState::new(ProcessOperator::new(process_manager));
|
||||
let control_plane =
|
||||
@@ -65,79 +57,25 @@ async fn main() -> anyhow::Result<()> {
|
||||
})
|
||||
.await?;
|
||||
|
||||
// Spawn a task that toggles the desired state periodically
|
||||
// tokio::spawn({
|
||||
// let control_plane = control_plane.clone();
|
||||
// async move {
|
||||
// let mut running = true;
|
||||
// loop {
|
||||
// tokio::time::sleep(Duration::from_secs(10)).await;
|
||||
// Spawn control plane
|
||||
tokio::spawn({
|
||||
let control_plane = control_plane.clone();
|
||||
async move {
|
||||
let _ = control_plane.execute().await;
|
||||
}
|
||||
});
|
||||
|
||||
// running = !running;
|
||||
// let desired_state = if running {
|
||||
// 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?;
|
||||
// Run TUI
|
||||
nocontrol_tui::run(control_plane).await?;
|
||||
|
||||
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
|
||||
#[derive(Clone)]
|
||||
pub struct ProcessOperator {
|
||||
process_manager: ProcessManager,
|
||||
|
||||
// Maps manifest name -> process handle ID in the ProcessManager
|
||||
process_ids: Arc<RwLock<HashMap<String, HandleID>>>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user