mirror of
https://github.com/norohind/jubilant-system.git
synced 2026-12-04 02:35:13 +03:00
Handle edge case with high squad ID
When already updated squad with high id but still running retrospectively so utils.get_last_known_id would return high id + 1 but not anymore
This commit is contained in:
3 files changed
+29
-4
No files matched your search
@@ -56,7 +56,8 @@ def discover():
|
||||
:return:
|
||||
"""
|
||||
|
||||
id_to_try = utils.get_last_known_id(db)
|
||||
# id_to_try = utils.get_last_known_id(db)
|
||||
# id_to_try = utils.get_next_id_for_discover(db) - 1
|
||||
tries: int = 0
|
||||
failed: list = list()
|
||||
TRIES_LIMIT_RETROSPECTIVELY: int = 5000
|
||||
@@ -64,7 +65,7 @@ def discover():
|
||||
|
||||
def smart_tries_limit(squad_id: int) -> int: # something smarter but still have to be better
|
||||
|
||||
if id_to_try < 65000:
|
||||
if squad_id < 65000:
|
||||
return TRIES_LIMIT_RETROSPECTIVELY
|
||||
|
||||
else:
|
||||
@@ -73,11 +74,12 @@ def discover():
|
||||
"""
|
||||
tries_limit, probably, should be something more smart because on retrospectively scan we can
|
||||
have large spaces of dead squadrons but when we are discovering on real time, large value of tries_limit
|
||||
will just waste our time and, probable, confuses FDEV
|
||||
will just waste our time and, probable, confuses FDEV
|
||||
*Outdated but it still can be more smart*
|
||||
"""
|
||||
|
||||
while True:
|
||||
id_to_try = id_to_try + 1
|
||||
id_to_try = utils.get_next_hole_id_for_discover(db)
|
||||
# logger.debug(f'Starting discover loop iteration, tries: {tries} of {tries_limit}, id to try {id_to_try}, '
|
||||
# f'failed list: {failed}')
|
||||
|
||||
|
||||
@@ -72,3 +72,10 @@ from squads_states
|
||||
where tag is not null
|
||||
order by inserted_timestamp asc
|
||||
limit ?;"""
|
||||
|
||||
select_first_hole_id: str = """select squad_id+1 as a
|
||||
from squads_states except
|
||||
select squad_id
|
||||
from squads_states
|
||||
order by a asc
|
||||
limit 1;"""
|
||||
@@ -309,3 +309,19 @@ def get_last_known_id(db_conn: sqlite3.Connection) -> int:
|
||||
else:
|
||||
logger.debug(f'last know id from DB: {sql_request_result[0]}')
|
||||
return sql_request_result[0]
|
||||
|
||||
|
||||
def get_next_hole_id_for_discover(db_conn: sqlite3.Connection) -> int:
|
||||
"""Returns first unexisting id in DB
|
||||
:param db_conn:
|
||||
:return: last known id if we iterate from 1 to ...
|
||||
"""
|
||||
|
||||
sql_req = db_conn.execute(sql_requests.select_first_hole_id).fetchone()
|
||||
if sql_req is None:
|
||||
logger.debug(f"Can't get last know id from DB, defaulting to 1")
|
||||
return 1
|
||||
|
||||
else:
|
||||
logger.debug(f'last know id from DB: {sql_req[0]}')
|
||||
return sql_req[0]
|
||||
Reference in new issue
Block a user