From d9e68799d80b31d70d8a560a5c0484ddb7070d79 Mon Sep 17 00:00:00 2001 From: extreme4all <> Date: Tue, 14 Nov 2023 17:01:37 +0100 Subject: [PATCH] cleaner sleep if end --- src/jobs/kafka/players/main.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/jobs/kafka/players/main.py b/src/jobs/kafka/players/main.py index 21fbced..679b8bf 100644 --- a/src/jobs/kafka/players/main.py +++ b/src/jobs/kafka/players/main.py @@ -101,9 +101,9 @@ async def get_data(receive_queue: Queue): url = f"{APPCONFIG.ENDPOINT}/v2/player/" while True: - sleep = None today = datetime.now().date() players, error = await get_request(url=url, params=params, headers=headers) + len_players = len(players) if error is not None: sleep_time = 30 @@ -111,10 +111,6 @@ async def get_data(receive_queue: Queue): await asyncio.sleep(sleep_time) continue - if len(players) < APPCONFIG.BATCH_SIZE: - _players = len(players) - sleep = 300 - players = await parse_data(players=players) logger.info({"reeived": len(players), "max_id": {params.get("player_id")}}) @@ -129,9 +125,10 @@ async def get_data(receive_queue: Queue): logger.info("New day!, resetting player_id to 0") params["player_id"] = 0 - if sleep: - logger.info(f"Received {_players}, sleeping: {sleep}") - await asyncio.sleep(sleep) + if len_players < APPCONFIG.BATCH_SIZE: + sleep_time = 300 + logger.info(f"Received {len_players}, sleeping: {sleep_time}") + await asyncio.sleep(sleep_time) async def main():