jaywonchung/pegasus

Watch filesystem events on `queue.yaml` instead of polling every 3 secs

jaywonchung opened this issue · 4 comments

Currently, when queue.yaml is empty, the scheduling loop just sleeps for three seconds and re-checks if there's any new commands. This is less responsive and it's basically polling.

Crates like notify does filesystem watching, but it's not async. Especially, since its watcher takes std::sync::mpsc::{Sender, Receiver} in its constructor and those are !Sync.

It seems like notify 5.0.0-pre.13 finally fixed this and allow users to provide a callback instead of a std::sync::mpsc::Sender.

Maybe we can wait until notify 5.0.0 is out.

Notes for future reference:

  1. We edit queue.yaml ourselves, so we need to remove events generated by ourselves.
  2. From the docs: If you use a delay of more than 30 seconds, you can avoid receiving repetitions of previous events on macOS.. So basically the delay we specify seems to be a trade-off between duplicate events and responsiveness. And there is not much advantage in using notify if we are to specify a delay larger than three seconds. Will have to look into this.