Simplify idle logging loop
Simplify idle logging loop

Summary:
Before this diff, we would sample and sleep for 1s in a loop, subtracting 1s
from the idle timeout until we hit zero, then log.

Instead of "counting" loops like this, we can just set up an infinite sampling
loop and combine with a timeout using Lwt.pick, which will cancel the sampling
loop once the timeout hits.

While unimportant, the event timing is more regular with this change. In
practice, collecting stats and waiting 1s takes longer than 1s, but we only
subtracted 1 from the counter. This imprecision adds up over 300s, causing the
actual duration to be 301.7 seconds in practice.

I also added a call to flush the logger, since otherwise we would buffer the
idle heartbeat events until the next recheck.

Reviewed By: nmote

Differential Revision: D25253975

fbshipit-source-id: 0a2ef2c94d920bdadde197fc525d154c1317c43d

mroch/flow,facebook/flow,mroch/flow,facebook/flow,facebook/flow,mroch/flow,mroch/flow,facebook/flow,mroch/flow,facebook/flow,mroch/flow,facebook/flow,mroch/flow,facebook/flow