mirror of
https://github.com/norohind/jubilant-system.git
synced 2025-06-05 09:43:00 +03:00
add update thursday mode
This commit is contained in:
parent
62befc58b7
commit
74e22f533b
18
main.py
18
main.py
@ -142,9 +142,11 @@ def discover(back_count: int = 0):
|
|||||||
tries = tries + 1
|
tries = tries + 1
|
||||||
|
|
||||||
|
|
||||||
def update(squad_id: int = None, amount_to_update: int = 1):
|
def update(squad_id: int = None, amount_to_update: int = 1, thursday_target: bool = False):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
:param thursday_target: if we aiming to update all squads before thursday (FDEV scheduled maintenance)
|
||||||
|
and we don't wanna update squads which already updated after previous thursday
|
||||||
:param squad_id: update specified squad, updates only that squad
|
:param squad_id: update specified squad, updates only that squad
|
||||||
:param amount_to_update: update specified amount, ignores when squad_id specified
|
:param amount_to_update: update specified amount, ignores when squad_id specified
|
||||||
:return:
|
:return:
|
||||||
@ -156,7 +158,17 @@ def update(squad_id: int = None, amount_to_update: int = 1):
|
|||||||
# suppress_absence is required because if we updating squad with some high id it may just don't exists yet
|
# suppress_absence is required because if we updating squad with some high id it may just don't exists yet
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug(f'Going to update {amount_to_update} squadrons')
|
logger.debug(f'Going to update {amount_to_update} squadrons with thursday_target = {thursday_target}')
|
||||||
|
|
||||||
|
if thursday_target:
|
||||||
|
prev_thursday = f'{utils.get_previous_thursday_date()} 10:30:00'
|
||||||
|
squads_id_to_update: list = db.execute(
|
||||||
|
sql_requests.select_squads_to_update_thursday_aimed, (prev_thursday, amount_to_update)).fetchall()
|
||||||
|
|
||||||
|
if len(squads_id_to_update) == 0:
|
||||||
|
logger.info(f'thursday_target and no squads to update')
|
||||||
|
|
||||||
|
else:
|
||||||
squads_id_to_update: list = db.execute(sql_requests.select_squads_to_update, (amount_to_update,)).fetchall()
|
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
|
for single_squad_to_update in squads_id_to_update: # if db is empty, then loop will not happen
|
||||||
@ -207,7 +219,7 @@ if __name__ == '__main__':
|
|||||||
while True:
|
while True:
|
||||||
can_be_shutdown = False
|
can_be_shutdown = False
|
||||||
|
|
||||||
update(amount_to_update=500)
|
update(amount_to_update=500, thursday_target=True)
|
||||||
if shutting_down:
|
if shutting_down:
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
@ -102,3 +102,8 @@ limit 2;"""
|
|||||||
select_important_before_delete: str = """select name, platform, member_count, tag, user_tags, created
|
select_important_before_delete: str = """select name, platform, member_count, tag, user_tags, created
|
||||||
from squads_view
|
from squads_view
|
||||||
where squad_id = ?;"""
|
where squad_id = ?;"""
|
||||||
|
|
||||||
|
select_squads_to_update_thursday_aimed: str = """select squad_id
|
||||||
|
from squads_view
|
||||||
|
where inserted_timestamp < ?
|
||||||
|
limit ?;"""
|
||||||
|
10
utils.py
10
utils.py
@ -483,3 +483,13 @@ def append_to_list_in_dict(dict_to_append: dict[str, list[str]], key: str, value
|
|||||||
dict_to_append.update({key: [value]})
|
dict_to_append.update({key: [value]})
|
||||||
|
|
||||||
return dict_to_append
|
return dict_to_append
|
||||||
|
|
||||||
|
|
||||||
|
def get_previous_thursday_date() -> str:
|
||||||
|
from datetime import date, timedelta
|
||||||
|
from calendar import THURSDAY
|
||||||
|
|
||||||
|
today = date.today()
|
||||||
|
offset = (today.weekday() - THURSDAY) % 7
|
||||||
|
last_wednesday = today - timedelta(days=offset)
|
||||||
|
return str(last_wednesday)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user