Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
move to Instant.elapsed() instead of time::Sleep timer (#833)
Browse files Browse the repository at this point in the history
In current tokio, time::sleep().elapsed does not update unless the Sleep is polled.  as such, the execute_pending_commands never fires.  This replaces the sleep().elapsed with Instant.elapsed().
  • Loading branch information
bmc-msft authored Apr 26, 2021
1 parent 99724b1 commit fde43a3
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/agent/onefuzz-supervisor/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::setup::*;
use crate::work::IWorkQueue;
use crate::worker::IWorkerRunner;

const PENDING_COMMANDS_DELAY: time::Duration = time::Duration::from_secs(10);

pub struct Agent {
coordinator: Box<dyn ICoordinator>,
reboot: Box<dyn IReboot>,
Expand Down Expand Up @@ -50,7 +52,7 @@ impl Agent {
}

pub async fn run(&mut self) -> Result<()> {
let mut delay = command_delay();
let mut instant = time::Instant::now();

// Tell the service that the agent has started.
//
Expand All @@ -68,9 +70,9 @@ impl Agent {

loop {
self.heartbeat.alive();
if delay.is_elapsed() {
if instant.elapsed() >= PENDING_COMMANDS_DELAY {
self.execute_pending_commands().await?;
delay = command_delay();
instant = time::Instant::now();
}

let done = self.update().await?;
Expand Down Expand Up @@ -268,7 +270,7 @@ impl Agent {
let cmd = self.coordinator.poll_commands().await?;

if let Some(cmd) = cmd {
debug!("agent received node command: {:?}", cmd);
info!("agent received node command: {:?}", cmd);
self.scheduler()?.execute_command(cmd).await?;
}

Expand All @@ -285,11 +287,6 @@ impl Agent {
}
}

fn command_delay() -> time::Sleep {
let delay = time::Duration::from_secs(10);
time::sleep(delay)
}

// The agent owns a `Scheduler`, which it must consume when driving its state
// transitions in `update()`. If `self.scheduler` is ever `None` outside of
// `update()`, then it is a fatal internal error.
Expand Down

0 comments on commit fde43a3

Please sign in to comment.