George3d6 / Inquisitor

An easily extensible, minimal footprint monitoring tool. (Still in the testing phase)
BSD 2-Clause "Simplified" License
30 stars 4 forks source link

Better sleep #12

Closed Deedasmi closed 6 years ago

Deedasmi commented 6 years ago

Agent now sleeps the required amount of time rather than one second every loop.

In theory, we could get rid of the existing ready function and if when_ready is negative then we run. I don't think it's worth it though.

Last two commits aren't related to this trait change directly, apologies if it causes conflicts with any of your work.

Deedasmi commented 6 years ago

There is an issue where when_ready could go negative which would cause problems. Need to re-think this.

George3d6 commented 6 years ago

An easy fix like expr > 0 ? expr : 0 would fix the above (but induce problem if one periodicity is set to 0).

George3d6 commented 6 years ago

I will get onto this project again myself later tonight and look at this.

Deedasmi commented 6 years ago

I added a default trait impl as a convenience function, but left it overrideable in case gather() was a long-running function or required more than just time, such as a file lock or some other condition that ready() could fail. However, I realized that if when_ready passes and ready() fails, when_ready will go negative and overflow into a massively long sleep time.

I still like the idea of supporting a non-time based ready check, but not sure how to do it at the moment. The only easy solution is making ready a &mut self call so it can reset its last_call. I'll think on it some more. If you think of something feel free to commit to my fork!

George3d6 commented 6 years ago

I think the solution here is:

a) Modify when_read to use:

let periodicty_fixed = if self.periodicity > 0 periodicity else 1 And used periodicty_fixed instead of self.periodicity in the fix

b) When checking the "when_ready" results add a map of:

map(x -> if x > 0 x else 0)

Atm I'm on my phone so i can't really make a commit

Deedasmi commented 6 years ago

That seems like a big gotcha for plugin developers though. Biggest problem I'm seeing now is that plugins don't have to be time based. Ready could be a ping, file check, or anything else.

Still, there are options

  1. Make when_ready an optional trait function and let some default value run when it's not implemented.
  2. Do away with it and sleep on a constant or runtime argument. It's really not that much of a resource drain. Hell, it could be in the agent config.
  3. Go fully async. Probably shouldn't with how immature rust still is there.

Leaning towards 2 and scraping this branch.

It's after 3 am and I have class tomorrow, so I should force myself to stop thinking about this lol