Update mode done, isn't tested; hooks TODO

This commit is contained in:
norohind 2021-10-25 00:16:21 +03:00
parent 2e0f13efd3
commit 69d81a05bb
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1
4 changed files with 51 additions and 5 deletions

View File

@ -72,6 +72,10 @@ DB tables
implementation notes:
1. If guilds stop their existing, then write a record to `squads_transactions` with fields as null except guild id
hooks (don't mismatch with DB hooks)
1. On properly_delete_squadron
2. On insertion new data to squads_states (don't forget handle news)
3.
legacy:
request bearer token from capi.demb.design

39
main.py
View File

@ -1,6 +1,7 @@
import sqlite3
import time
import sql_requests
import utils
from EDMCLogging import get_main_logger
@ -32,7 +33,6 @@ Two modes:
delete(failed_squad)
failed_squad = list()
else (fail)
failed.append(id_to_try)
tries = tries + 1
@ -42,6 +42,10 @@ Two modes:
2. Update exists
get oldest updated existing squad
if DB is empty
return
update it
if squad still exists
process triggers
@ -53,10 +57,19 @@ def discover_triggers(squad_info: dict):
def discover():
"""Discover new squads
:return:
"""
id_to_try = utils.get_last_known_id(db)
tries: int = 0
failed: list = list()
tries_limit: int = 5000
"""
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"""
while True:
id_to_try = id_to_try + 1
@ -77,7 +90,7 @@ def discover():
failed = list()
else: # should be only False
else: # fail, should be only False
logger.debug(f'Fail on discovery for {id_to_try} ID')
failed.append(id_to_try)
tries = tries + 1
@ -86,3 +99,25 @@ def discover():
discover()
def update(squad_id: int = None, amount_to_update: int = 1):
"""
:param squad_id: update specified squad, updates only that squad
:param amount_to_update: update specified amount, ignores when squad_id specified
:return:
"""
if isinstance(squad_id, int):
logger.debug(f'Going to update one specified squadron: {squad_id} ID')
utils.update_squad_info(squad_id, db)
return
logger.debug(f'Going to update {amount_to_update} squadrons')
squads_id_to_update: list = db.execute(sql_requests.select_squads_to_update, (amount_to_update,)).fetchall()
for single_squad_to_update in squads_id_to_update: # if db is empty, then loop will not happen
id_to_update: int = single_squad_to_update[0]
logger.debug(f'Updating {id_to_update}')
utils.update_squad_info(id_to_update, db)

View File

@ -65,4 +65,9 @@ where squad_id = ? and tag is null"""
select_last_known_id: str = """select squad_id
from squads_states
order by squad_id desc
limit 1;"""
limit 1;"""
select_squads_to_update: str = """select squad_id
from squads_states
order by inserted_timestamp asc
limit = ?;"""

View File

@ -164,6 +164,7 @@ def update_squad_info(squad_id: int, db_conn: sqlite3.Connection, suppress_absen
"""
How it should works?
*properly delete squad in our DB mean write to squads_states record with all null except ID
Request squad's info
if squad is properly deleted in our DB
@ -177,9 +178,10 @@ def update_squad_info(squad_id: int, db_conn: sqlite3.Connection, suppress_absen
if squad doesn't exists FDEV
if squad in DB
if isn't deleted in our DB
write to squads_states record with all null except ID (it will mean that squad was deleted)
properly delete squad
else if not suppress_absence
write to squads_states record with all null except ID (it will mean that squad was deleted)
properly delete squad