Skip to content

Commit

Permalink
cleaner sleep if end
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Nov 14, 2023
1 parent cafd469 commit d9e6879
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/jobs/kafka/players/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,16 @@ 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
logger.info(f"sleeping {sleep_time}")
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")}})

Expand All @@ -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():
Expand Down

0 comments on commit d9e6879

Please sign in to comment.