ppbbww

Pillar Point boats, birds, and waves watcher
git clone git@abtrout.com:ppbbww.git
Log | Files | Refs | README | LICENSE

commit 53fe4cadb08339d37771c9b17fcc5405cf974d64
parent 1587e3abc9b87f0e959b900dee5e6a496a42ff6a
Author: david cochran <about.trout@gmail.com>
Date:   Thu, 27 Mar 2025 21:05:16 -0700

improve retry and backoff strategy

Diffstat:
Mppboatwatch/ppbbww.py | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/ppboatwatch/ppbbww.py b/ppboatwatch/ppbbww.py @@ -21,9 +21,12 @@ async def sample_stream(frames_q, sampler, min_delay, max_delay, day_start, day_ fail_count, max_failures = 0, 5 while True: try: + backoff = (2 ** fail_count) - 1 + random.uniform(0, 2*fail_count) + logging.warning(f"[sample_stream]: Sleeping {backoff} for backoff ...") + await asyncio.sleep(backoff) + frames = await sampler.get_recent_frames() logging.warning(f"[sample_stream]: Extracted {len(frames)} recent frames") - assert len(frames) > 0, "No frames extracted" await frames_q.put(frames[0].path) for frame in frames[1:]: # only keep 1 frame os.remove(frame) @@ -31,9 +34,9 @@ async def sample_stream(frames_q, sampler, min_delay, max_delay, day_start, day_ except Exception as ex: logging.error(f"[sample_stream]: Failed to get_recent_frames: {ex}") fail_count += 1 - if fail_count >= max_failures: - logging.warning("[sample_stream]: Too many download failures. Killing program!") - sys.exit(1) + #if fail_count >= max_failures: + # logging.warning("[sample_stream]: Too many download failures. Killing program!") + # sys.exit(1) if day_start <= datetime.now().time() <= day_end: delay = random.randint(min_delay, max_delay)