Skip to content

Commit

Permalink
Fix #3: limit loop to at most once every 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
robnagler authored Nov 22, 2024
2 parents 373ff61 + 1449fa0 commit 7e9f94e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lume-impact-live-demo-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,11 @@ def run1():
if __name__ == '__main__':
# TODO debug mode
import traceback
import time

_ITERATION_MIN_FREQUENCY_SECS = 5 * 60
while True:
start_time = time.time()
try:
result = run1()
sleep(10)
Expand All @@ -602,6 +605,11 @@ def run1():
break
else:
logger.debug(traceback.format_exc())
logger.info('Something BAD happened. Sleeping for 10 s ...')
logger.info('Something BAD happened. Sleeping for 10 s ...')
sleep(10)

finally:
elapsed_time = time.time() - start_time
if elapsed_time < _ITERATION_MIN_FREQUENCY_SECS:
s = _ITERATION_MIN_FREQUENCY_SECS - elapsed_time
logger.info(f'Sleeping for {s} seconds')
time.sleep(s)

0 comments on commit 7e9f94e

Please sign in to comment.