LucaR84 commited on
Commit
cf35b5e
·
1 Parent(s): 396f8ed
Files changed (3) hide show
  1. .gitignore +3 -0
  2. app.py +2 -1
  3. sync_hc/__init__.py +27 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ **/__pycache__/
2
+ .history/*
3
+ .DS_Store
app.py CHANGED
@@ -7,6 +7,7 @@ from contextlib import asynccontextmanager
7
  from pydantic import BaseModel
8
 
9
  # Import from the new module
 
10
  from models.model_manager import create_model_manager, GenerationRequest, GenerationResponse
11
 
12
  # Initialize FastAPI app with OpenAPI metadata
@@ -102,4 +103,4 @@ async def internal_error_handler(request, exc):
102
 
103
  if __name__ == "__main__":
104
  import uvicorn
105
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
7
  from pydantic import BaseModel
8
 
9
  # Import from the new module
10
+ import sync_hc
11
  from models.model_manager import create_model_manager, GenerationRequest, GenerationResponse
12
 
13
  # Initialize FastAPI app with OpenAPI metadata
 
103
 
104
  if __name__ == "__main__":
105
  import uvicorn
106
+ uvicorn.run(app, host="0.0.0.0", port=7860)
sync_hc/__init__.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import time
3
+ import os
4
+ from threading import Timer
5
+
6
+ # Get config from environment variables
7
+ URL = os.getenv('MASTER_URL', 'http://localhost:8000/hc')
8
+ HOST_URL = os.getenv('SENDER_URL', 'http://my-sender-host.com')
9
+ INTERVAL = int(os.getenv('SENDER_INTERVAL', '5')) # seconds
10
+
11
+ def send_timestamp():
12
+ try:
13
+ response = requests.get(URL, params={
14
+ 'timestamp': time.time(),
15
+ 'host_url': HOST_URL
16
+ })
17
+ print(f"Sent timestamp to {URL}: {response.status_code}")
18
+ except Exception as e:
19
+ print(f"Error sending timestamp to {URL}: {type(e).__name__}: {e}")
20
+
21
+ # Schedule next call
22
+ Timer(INTERVAL, send_timestamp).start()
23
+ print(f"Scheduled next timestamp send in {INTERVAL} seconds")
24
+
25
+ # Start the first call
26
+ print(f"Starting timestamp sender to {URL} every {INTERVAL} seconds")
27
+ send_timestamp()