Spaces:
Running
Running
refactor: update cron interval to 10 minutes and streamline keepalive request logging and handling
Browse files- cloudflare-keepalive-setup.py +2 -5
- health-server.js +0 -3
cloudflare-keepalive-setup.py
CHANGED
|
@@ -65,10 +65,7 @@ def render_keepalive_worker(target_url: str) -> str:
|
|
| 65 |
}});
|
| 66 |
|
| 67 |
addEventListener("scheduled", (event) => {{
|
| 68 |
-
event.waitUntil((
|
| 69 |
-
const result = await ping("cron");
|
| 70 |
-
console.log("Keepalive ping executed:", JSON.stringify(result));
|
| 71 |
-
}})());
|
| 72 |
}});
|
| 73 |
|
| 74 |
const TARGET_URL = {json.dumps(target_url)};
|
|
@@ -155,7 +152,7 @@ def setup_keepalive_worker(api_token: str, account_id: str, subdomain: str) -> N
|
|
| 155 |
write_keepalive_status({"configured": False, "status": "skipped", "message": "SPACE_HOST could not be determined."})
|
| 156 |
return
|
| 157 |
|
| 158 |
-
cron = os.environ.get("CLOUDFLARE_KEEPALIVE_CRON", "* * * * *").strip()
|
| 159 |
space_host = space_host.removeprefix("https://").removeprefix("http://").split("/")[0]
|
| 160 |
target_url = os.environ.get("CLOUDFLARE_KEEPALIVE_URL", f"https://{space_host}/health").strip()
|
| 161 |
worker_name = derive_keepalive_worker_name()
|
|
|
|
| 65 |
}});
|
| 66 |
|
| 67 |
addEventListener("scheduled", (event) => {{
|
| 68 |
+
event.waitUntil(ping("cron"));
|
|
|
|
|
|
|
|
|
|
| 69 |
}});
|
| 70 |
|
| 71 |
const TARGET_URL = {json.dumps(target_url)};
|
|
|
|
| 152 |
write_keepalive_status({"configured": False, "status": "skipped", "message": "SPACE_HOST could not be determined."})
|
| 153 |
return
|
| 154 |
|
| 155 |
+
cron = os.environ.get("CLOUDFLARE_KEEPALIVE_CRON", "*/10 * * * *").strip()
|
| 156 |
space_host = space_host.removeprefix("https://").removeprefix("http://").split("/")[0]
|
| 157 |
target_url = os.environ.get("CLOUDFLARE_KEEPALIVE_URL", f"https://{space_host}/health").strip()
|
| 158 |
worker_name = derive_keepalive_worker_name()
|
health-server.js
CHANGED
|
@@ -531,9 +531,6 @@ const server = http.createServer(async (req, res) => {
|
|
| 531 |
}
|
| 532 |
|
| 533 |
if (path === "/health" || path === `${APP_BASE}/health`) {
|
| 534 |
-
if (req.headers["user-agent"] === "HuggingMess Cloudflare KeepAlive") {
|
| 535 |
-
console.log(`[${new Date().toISOString()}] Received keepalive ping from Cloudflare.`);
|
| 536 |
-
}
|
| 537 |
const data = await statusPayload();
|
| 538 |
res.writeHead(data.ok ? 200 : 503, { "content-type": "application/json" });
|
| 539 |
res.end(
|
|
|
|
| 531 |
}
|
| 532 |
|
| 533 |
if (path === "/health" || path === `${APP_BASE}/health`) {
|
|
|
|
|
|
|
|
|
|
| 534 |
const data = await statusPayload();
|
| 535 |
res.writeHead(data.ok ? 200 : 503, { "content-type": "application/json" });
|
| 536 |
res.end(
|