ummmar commited on
Commit
48efd6d
·
verified ·
1 Parent(s): 25e813a

Update keep_alive.py

Browse files
Files changed (1) hide show
  1. keep_alive.py +5 -4
keep_alive.py CHANGED
@@ -33,10 +33,11 @@ try:
33
  print("✅ Worker script deployed.")
34
  except Exception as e:
35
  print(f"❌ Worker deploy failed: {e}")
36
- exit(1)
 
37
 
38
- # 2. Wait briefly for propagation
39
- time.sleep(2)
40
 
41
  # 3. Set Cron Trigger
42
  cron_payload = {"schedules": [{"cron": "*/10 * * * *"}]}
@@ -47,7 +48,7 @@ try:
47
  json=cron_payload
48
  )
49
  if res.status_code == 400:
50
- # Sometimes 400 means the worker isn't ready yet, retry once
51
  time.sleep(5)
52
  res = requests.put(
53
  f"https://api.cloudflare.com/client/v4/accounts/{CF_ACCOUNT_ID}/workers/scripts/{WORKER_NAME}/schedules",
 
33
  print("✅ Worker script deployed.")
34
  except Exception as e:
35
  print(f"❌ Worker deploy failed: {e}")
36
+ # Do not exit here, let the space run without keep-alive if CF fails
37
+ exit(0)
38
 
39
+ # 2. Wait for propagation
40
+ time.sleep(3)
41
 
42
  # 3. Set Cron Trigger
43
  cron_payload = {"schedules": [{"cron": "*/10 * * * *"}]}
 
48
  json=cron_payload
49
  )
50
  if res.status_code == 400:
51
+ print("⚠️ Cron setup returned 400. Retrying in 5 seconds...")
52
  time.sleep(5)
53
  res = requests.put(
54
  f"https://api.cloudflare.com/client/v4/accounts/{CF_ACCOUNT_ID}/workers/scripts/{WORKER_NAME}/schedules",