Improve use of last_refresh + rate wait.

This commit is contained in:
voussoir 2022-01-09 21:59:18 -08:00
parent 8840599be0
commit 06d45c4e1a
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -76,16 +76,19 @@ def init_ycdldb(*args, **kwargs):
def refresher_thread(rate): def refresher_thread(rate):
global last_refresh global last_refresh
while True: while True:
next_refresh = last_refresh + rate # If the user pressed the refresh button, the thread will wake from
wait = next_refresh - time.time() # sleep and find that it should go back to sleep for a little longer.
if wait > 0: while True:
next_refresh = last_refresh + rate
wait = next_refresh - time.time()
if wait <= 0:
break
time.sleep(wait) time.sleep(wait)
continue
log.info('Starting refresh job.') log.info('Starting refresh job.')
thread_kwargs = {'force': False, 'skip_failures': True}
refresh_job = threading.Thread( refresh_job = threading.Thread(
target=ycdldb.refresh_all_channels, target=ycdldb.refresh_all_channels,
kwargs=thread_kwargs, kwargs={'force': False, 'skip_failures': True},
daemon=True, daemon=True,
) )
refresh_job.start() refresh_job.start()