Skip to main content

Set Waiting Time

Last updated on

Set the maximum time the service will wait for another player while matchmaking.

# 15. Wait for another user.
elapsed_time = 0.0
active_matchmaking_requests_summary = None
other_matchmaking_request = None
while elapsed_time < FIND_OTHER_USER_MAX_DURATION:
active_matchmaking_requests_summary, error = get_active_matchmaking_requests_summary(
redis_client,
namespace,
env.game_mode
)
if error:
return error
other_matchmaking_request = active_matchmaking_requests_summary.get_other_matchmaking_request(user_id)
if other_matchmaking_request:
break
time.sleep(FIND_OTHER_USER_CHECK_INTERVAL)
elapsed_time += FIND_OTHER_USER_CHECK_INTERVAL
log_wait(f"waiting for other players.. {elapsed_time:.2f}/{FIND_OTHER_USER_MAX_DURATION:.2f}s")
if not other_matchmaking_request:
return create_response(408, "Timed out! Not enough players.")
log_done(f"find other user ({other_matchmaking_request['user_id']})")

party_id = other_matchmaking_request["party_id"]
user_ids = list(active_matchmaking_requests_summary.unique_user_ids)
other_user_ids = list(active_matchmaking_requests_summary.get_other_user_ids(user_id))