Spaces:
Sleeping
Sleeping
Commit ·
421e7e4
1
Parent(s): baebc75
proxy pool race condition fixed
Browse files- freeplay2api.py +12 -13
freeplay2api.py
CHANGED
|
@@ -167,7 +167,7 @@ class FreeplayClient:
|
|
| 167 |
"referer": "https://app.freeplay.ai/signup",
|
| 168 |
}
|
| 169 |
|
| 170 |
-
max_retries =
|
| 171 |
for attempt in range(max_retries):
|
| 172 |
proxy_info = None
|
| 173 |
try:
|
|
@@ -224,8 +224,6 @@ class FreeplayClient:
|
|
| 224 |
except Exception as e:
|
| 225 |
logging.error(f"An unexpected error occurred during registration on attempt {attempt + 1}/{max_retries}: {e}. Retrying...")
|
| 226 |
|
| 227 |
-
time.sleep(1)
|
| 228 |
-
|
| 229 |
logging.error("Failed to register a new account after multiple retries.")
|
| 230 |
return None
|
| 231 |
|
|
@@ -364,16 +362,17 @@ class KeyMaintainer(threading.Thread):
|
|
| 364 |
]
|
| 365 |
needed = self.config["ACTIVE_KEY_THRESHOLD"] - len(healthy_accounts)
|
| 366 |
|
| 367 |
-
|
| 368 |
-
logging.info(f"Healthy accounts ({len(healthy_accounts)}) below threshold. Need to register {needed} new accounts.")
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
|
|
|
| 377 |
|
| 378 |
except Exception as e:
|
| 379 |
logging.error(f"Error in KeyMaintainer cycle: {e}")
|
|
|
|
| 167 |
"referer": "https://app.freeplay.ai/signup",
|
| 168 |
}
|
| 169 |
|
| 170 |
+
max_retries = 10
|
| 171 |
for attempt in range(max_retries):
|
| 172 |
proxy_info = None
|
| 173 |
try:
|
|
|
|
| 224 |
except Exception as e:
|
| 225 |
logging.error(f"An unexpected error occurred during registration on attempt {attempt + 1}/{max_retries}: {e}. Retrying...")
|
| 226 |
|
|
|
|
|
|
|
| 227 |
logging.error("Failed to register a new account after multiple retries.")
|
| 228 |
return None
|
| 229 |
|
|
|
|
| 362 |
]
|
| 363 |
needed = self.config["ACTIVE_KEY_THRESHOLD"] - len(healthy_accounts)
|
| 364 |
|
| 365 |
+
while needed > 0:
|
| 366 |
+
logging.info(f"Healthy accounts ({len(healthy_accounts)}) below threshold. Need to register {needed} new accounts. Retrying immediately.")
|
| 367 |
+
new_account = self.client.register()
|
| 368 |
+
if new_account:
|
| 369 |
+
self.manager.add_account(new_account)
|
| 370 |
+
|
| 371 |
+
healthy_accounts = [
|
| 372 |
+
acc for acc in self.manager.get_all_accounts()
|
| 373 |
+
if acc.get("balance", 0) > self.config["LOW_BALANCE_THRESHOLD"]
|
| 374 |
+
]
|
| 375 |
+
needed = self.config["ACTIVE_KEY_THRESHOLD"] - len(healthy_accounts)
|
| 376 |
|
| 377 |
except Exception as e:
|
| 378 |
logging.error(f"Error in KeyMaintainer cycle: {e}")
|