Spaces:
Sleeping
Sleeping
Create pot_server.py
Browse files- src/api/pot_server.py +31 -0
src/api/pot_server.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import logging
|
| 3 |
+
import time
|
| 4 |
+
import urllib.request
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
logger = logging.getLogger(__name__)
|
| 8 |
+
_SERVER_ENTRY = Path("/opt/bgutil-provider/server/build/main.js")
|
| 9 |
+
|
| 10 |
+
class POTServer:
|
| 11 |
+
def __init__(self):
|
| 12 |
+
self._proc = None
|
| 13 |
+
|
| 14 |
+
def start(self):
|
| 15 |
+
if not _SERVER_ENTRY.exists():
|
| 16 |
+
logger.error("❌ POT server script not found!")
|
| 17 |
+
return False
|
| 18 |
+
|
| 19 |
+
logger.info("🚀 Starting Node.js POT solver...")
|
| 20 |
+
self._proc = subprocess.Popen(["node", str(_SERVER_ENTRY)])
|
| 21 |
+
|
| 22 |
+
# انتظر ثواني يتأكد إنه اشتغل
|
| 23 |
+
time.sleep(5)
|
| 24 |
+
return True
|
| 25 |
+
|
| 26 |
+
def stop(self):
|
| 27 |
+
if self._proc:
|
| 28 |
+
self._proc.terminate()
|
| 29 |
+
logger.info("🛑 POT server stopped.")
|
| 30 |
+
|
| 31 |
+
pot_server = POTServer()
|