Spaces:
Running
Running
Commit ·
57abcef
1
Parent(s): 61c345b
push trigger the first time
Browse files- Dockerfile +2 -0
- README.md +1 -1
- app.py +54 -9
Dockerfile
CHANGED
|
@@ -7,3 +7,5 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 7 |
|
| 8 |
EXPOSE 7860
|
| 9 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
EXPOSE 7860
|
| 9 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 10 |
+
|
| 11 |
+
|
README.md
CHANGED
|
@@ -6,5 +6,5 @@ colorTo: blue
|
|
| 6 |
sdk: docker
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
-
short_description: trigger
|
| 10 |
---
|
|
|
|
| 6 |
sdk: docker
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
+
short_description: HF trigger for Db3_update
|
| 10 |
---
|
app.py
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
-
import
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
@app.get("/")
|
| 7 |
def home():
|
| 8 |
-
return {"status": "running", "message": "
|
| 9 |
|
| 10 |
@app.get("/run")
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# from fastapi import FastAPI
|
| 2 |
+
# import datetime, os
|
| 3 |
+
|
| 4 |
+
# app = FastAPI()
|
| 5 |
+
|
| 6 |
+
# @app.get("/")
|
| 7 |
+
# def home():
|
| 8 |
+
# return {"status": "running", "message": "trigger space is alive"}
|
| 9 |
+
|
| 10 |
+
# @app.get("/run")
|
| 11 |
+
# def run_task():
|
| 12 |
+
# """Simple test endpoint that creates a text file in /tmp."""
|
| 13 |
+
# filename = "/tmp/test.txt"
|
| 14 |
+
# with open(filename, "a") as f:
|
| 15 |
+
# f.write(f"Triggered at {datetime.datetime.utcnow().isoformat()}\n")
|
| 16 |
+
# print(f"✅ File created at {filename}")
|
| 17 |
+
# return {"status": "ok", "message": "test.txt created"}
|
| 18 |
+
|
| 19 |
from fastapi import FastAPI
|
| 20 |
+
import requests, time, os, datetime
|
| 21 |
|
| 22 |
app = FastAPI()
|
| 23 |
|
| 24 |
+
DB3_URL = "https://alesamodio-db3-update.hf.space"
|
| 25 |
+
SECRET = os.getenv("CRON_SECRET", "Cielo2017.tiamo")
|
| 26 |
+
|
| 27 |
@app.get("/")
|
| 28 |
def home():
|
| 29 |
+
return {"status": "running", "message": "Trigger space alive"}
|
| 30 |
|
| 31 |
@app.get("/run")
|
| 32 |
+
def trigger_db3():
|
| 33 |
+
log = []
|
| 34 |
+
start = datetime.datetime.utcnow()
|
| 35 |
+
log.append(f"🕓 {start.isoformat()} | Starting trigger for Db3_update")
|
| 36 |
+
|
| 37 |
+
for attempt in range(1, 41): # ≈ 20 min total (30 s × 40)
|
| 38 |
+
try:
|
| 39 |
+
# 1️⃣ check if Db3_update responds
|
| 40 |
+
r = requests.get(DB3_URL, timeout=15)
|
| 41 |
+
if r.status_code == 200 and '"status"' in r.text:
|
| 42 |
+
log.append(f"✅ Attempt {attempt}: space ready, calling /run")
|
| 43 |
+
run_url = f"{DB3_URL}/run?secret={SECRET}"
|
| 44 |
+
run_resp = requests.get(run_url, timeout=120)
|
| 45 |
+
log.append(f"Response: {run_resp.text}")
|
| 46 |
+
if '"status":"ok"' in run_resp.text:
|
| 47 |
+
log.append("🎉 DB3 update completed successfully!")
|
| 48 |
+
break
|
| 49 |
+
else:
|
| 50 |
+
log.append("⚠️ DB3 responded but not ok, retrying…")
|
| 51 |
+
else:
|
| 52 |
+
log.append(f"⏳ Attempt {attempt}: not ready yet")
|
| 53 |
+
except Exception as e:
|
| 54 |
+
log.append(f"❌ Attempt {attempt}: error {e}")
|
| 55 |
+
time.sleep(30)
|
| 56 |
+
|
| 57 |
+
finish = datetime.datetime.utcnow()
|
| 58 |
+
duration = (finish - start).total_seconds()
|
| 59 |
+
log.append(f"🏁 Finished at {finish.isoformat()} (duration {duration:.0f}s)")
|
| 60 |
+
print("\n".join(log))
|
| 61 |
+
return {"status": "done", "log": log}
|
| 62 |
+
|