pegasus icon indicating copy to clipboard operation
pegasus copied to clipboard

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

Open jaywonchung opened this issue 4 years ago • 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.

jaywonchung avatar Feb 07 '22 00:02 jaywonchung

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.

NobodyXu avatar Feb 07 '22 00:02 NobodyXu

Maybe we can wait until notify 5.0.0 is out.

NobodyXu avatar Feb 07 '22 00:02 NobodyXu

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.

jaywonchung avatar Feb 07 '22 01:02 jaywonchung

Notify 5.0.0 is out. https://github.com/notify-rs/notify/blob/main/examples/async_monitor.rs

jaywonchung avatar Aug 31 '22 02:08 jaywonchung