ilang-ai commited on
Commit
59295ba
·
1 Parent(s): a230509

fix: HF Space health check on port 7860 + Node.js 24 Actions warning

Browse files

- Add HTTP health check thread (port 7860) so HF Space doesn't restart container
- Add EXPOSE 7860 to Dockerfile
- Add FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 to both workflows

.github/workflows/sync-hf-datasets.yml CHANGED
@@ -4,6 +4,9 @@ on:
4
  push:
5
  branches: [main]
6
 
 
 
 
7
  jobs:
8
  sync:
9
  runs-on: ubuntu-latest
 
4
  push:
5
  branches: [main]
6
 
7
+ env:
8
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
9
+
10
  jobs:
11
  sync:
12
  runs-on: ubuntu-latest
.github/workflows/sync-hf.yml CHANGED
@@ -4,6 +4,9 @@ on:
4
  push:
5
  branches: [main]
6
 
 
 
 
7
  jobs:
8
  sync:
9
  runs-on: ubuntu-latest
 
4
  push:
5
  branches: [main]
6
 
7
+ env:
8
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
9
+
10
  jobs:
11
  sync:
12
  runs-on: ubuntu-latest
Dockerfile CHANGED
@@ -9,4 +9,6 @@ COPY . .
9
 
10
  RUN mkdir -p data
11
 
 
 
12
  CMD ["python", "bot.py"]
 
9
 
10
  RUN mkdir -p data
11
 
12
+ EXPOSE 7860
13
+
14
  CMD ["python", "bot.py"]
bot.py CHANGED
@@ -4,6 +4,8 @@ import os
4
  import time as _time
5
  import hashlib as _hashlib
6
  import asyncio
 
 
7
 
8
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
9
 
@@ -408,9 +410,29 @@ async def handle_tos_callback(update: Update, context: ContextTypes.DEFAULT_TYPE
408
  await context.bot.leave_chat(chat_id)
409
 
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  # ==================== Main ====================
412
 
413
  def main():
 
 
414
  # Ensure data directory exists
415
  os.makedirs(os.path.dirname(config.DB_PATH) or "data", exist_ok=True)
416
 
 
4
  import time as _time
5
  import hashlib as _hashlib
6
  import asyncio
7
+ import threading
8
+ from http.server import HTTPServer, BaseHTTPRequestHandler
9
 
10
  sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
11
 
 
410
  await context.bot.leave_chat(chat_id)
411
 
412
 
413
+ # ==================== Health Check (HF Space) ====================
414
+
415
+ class HealthHandler(BaseHTTPRequestHandler):
416
+ def do_GET(self):
417
+ self.send_response(200)
418
+ self.end_headers()
419
+ self.wfile.write(b"OK")
420
+ def log_message(self, *args):
421
+ pass
422
+
423
+ def start_health_server():
424
+ port = int(os.environ.get("PORT", 7860))
425
+ server = HTTPServer(("0.0.0.0", port), HealthHandler)
426
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
427
+ thread.start()
428
+ logger.info("Health check on port " + str(port))
429
+
430
+
431
  # ==================== Main ====================
432
 
433
  def main():
434
+ # Health check for HF Space
435
+ start_health_server()
436
  # Ensure data directory exists
437
  os.makedirs(os.path.dirname(config.DB_PATH) or "data", exist_ok=True)
438