rpc: Do not repeat within additional while loop

We additionally add a delay at the end of the loop to prevent accidental spam.
This commit is contained in:
Spotlight 2024-10-02 20:44:41 -05:00
parent 45c52a9cbf
commit 5755a272de
No known key found for this signature in database
GPG Key ID: 874AA355B3209BDC

View File

@ -230,7 +230,9 @@ while True:
)
inactive_users = session.scalars(inactive_query).all()
print('[CLEARING INACTIVES; BATCH OF %s]' % len(inactive_users))
if len(inactive_users) > 0:
print('[INACTIVES; BATCH OF %s]' % len(inactive_users))
for inactive_user in inactive_users:
api_client = APIClient(inactive_user)
try:
@ -243,11 +245,8 @@ while True:
time.sleep(delay)
# Finally, we'll refresh presences for all remaining users.
wait = time.time()
while time.time() - wait <= 1200:
discord_friends = session.scalars(select(DiscordFriends).where(DiscordFriends.active)).all()
print('[BATCH OF %s USERS]' % len(discord_friends))
if len(discord_friends) < 1:
time.sleep(delay)
continue
@ -309,3 +308,6 @@ while True:
except HTTPError:
api_client.delete_discord_user()
time.sleep(delay)
# Sleep for 5x our delay.
time.sleep(delay * 5)