Add back scan on discover

This commit is contained in:
norohind 2021-11-03 14:30:07 +03:00
parent 7545514269
commit 62befc58b7
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1
2 changed files with 17 additions and 3 deletions

15
main.py
View File

@ -75,9 +75,9 @@ def shutdown_callback(sig, frame) -> None:
exit(0)
def discover():
def discover(back_count: int = 0):
"""Discover new squads
:param back_count: int how many squads back we should check, it is helpful to recheck newly created squads
:return:
"""
@ -104,6 +104,15 @@ def discover():
*Outdated but it still can be more smart*
"""
if back_count != 0:
logger.debug(f'back_count = {back_count}')
squad_id: list
for squad_id in db.execute(sql_requests.select_new_squads_to_update, (back_count,)).fetchall():
squad_id: int = squad_id[0]
logger.debug(f'Back updating {squad_id}')
utils.update_squad_info(squad_id, db)
while True:
if shutting_down:
@ -208,7 +217,7 @@ if __name__ == '__main__':
can_be_shutdown = False
logger.info('Discovering')
discover()
discover(back_count=20)
if shutting_down:
exit(0)

View File

@ -72,6 +72,11 @@ from squads_view
order by inserted_timestamp asc
limit ?;"""
select_new_squads_to_update: str = """select squad_id
from squads_view
order by squad_id desc
limit ?;"""
select_first_hole_id: str = """select squad_id+1 as a
from squads_states except
select squad_id