Add backoff to do_tasks.

This commit is contained in:
voussoir 2020-11-26 18:19:10 -08:00
parent 4b23d311c3
commit 67108ec617

View file

@ -7,6 +7,9 @@ import send2trash
import sys import sys
import time import time
from voussoirkit import backoff
bo = backoff.Linear(m=1, b=5, max=300)
def get_task_files(): def get_task_files():
return [f for f in os.listdir() if (os.path.isfile(f) and f.endswith('.task'))] return [f for f in os.listdir() if (os.path.isfile(f) and f.endswith('.task'))]
@ -27,9 +30,11 @@ def do_tasks_forever():
while True: while True:
print(time.strftime('%H:%M:%S'), 'Looking for tasks.') print(time.strftime('%H:%M:%S'), 'Looking for tasks.')
task_files = get_task_files() task_files = get_task_files()
if task_files:
bo.reset()
do_tasks(task_files) do_tasks(task_files)
try: try:
time.sleep(10) time.sleep(bo.next())
except KeyboardInterrupt: except KeyboardInterrupt:
break break