register turtles in scheduler when they make their first request
This commit is contained in:
parent
caef523357
commit
4e56ae770e
3 changed files with 4 additions and 5 deletions
|
@ -156,11 +156,7 @@ async fn read_from_disk(kill: watch::Sender<()>) -> anyhow::Result<LiveState> {
|
||||||
depots,
|
depots,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut live = LiveState::from_save(saved, scheduler, kill);
|
let live = LiveState::from_save(saved, scheduler, kill);
|
||||||
|
|
||||||
for turtle in live.turtles.iter() {
|
|
||||||
live.tasks.add_turtle(&TurtleCommander::new(turtle.read().await.name,&live).await.unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(live)
|
Ok(live)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ impl Scheduler {
|
||||||
if self.turtles.iter().any(|(t,_)| t.name() == name ) {
|
if self.turtles.iter().any(|(t,_)| t.name() == name ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
info!("registered {}", name.to_owned().to_str());
|
||||||
self.turtles.push((
|
self.turtles.push((
|
||||||
turtle.clone(),
|
turtle.clone(),
|
||||||
None
|
None
|
||||||
|
|
|
@ -222,6 +222,7 @@ pub(crate) async fn command(
|
||||||
) -> Json<turtle::TurtleCommand> {
|
) -> Json<turtle::TurtleCommand> {
|
||||||
trace!("reply from turtle {id}: {req:?}");
|
trace!("reply from turtle {id}: {req:?}");
|
||||||
let state_guard = state.clone().read_owned().await;
|
let state_guard = state.clone().read_owned().await;
|
||||||
|
let turtle_commander = state_guard.get_turtle(id).await;
|
||||||
|
|
||||||
if id as usize > state_guard.turtles.len() {
|
if id as usize > state_guard.turtles.len() {
|
||||||
return Json(turtle::TurtleCommand::Update);
|
return Json(turtle::TurtleCommand::Update);
|
||||||
|
@ -237,6 +238,7 @@ pub(crate) async fn command(
|
||||||
if Instant::elapsed(&state.clone().read().await.started).as_secs_f64() > STARTUP_ALLOWANCE {
|
if Instant::elapsed(&state.clone().read().await.started).as_secs_f64() > STARTUP_ALLOWANCE {
|
||||||
let schedule = &mut state.write().await.tasks;
|
let schedule = &mut state.write().await.tasks;
|
||||||
trace!("idle, polling");
|
trace!("idle, polling");
|
||||||
|
schedule.add_turtle(&turtle_commander.unwrap());
|
||||||
schedule.poll().await;
|
schedule.poll().await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue