Skip to content

Commit e151a3a

Browse files
committed
Update health when the updater fails
1 parent af6a726 commit e151a3a

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

root/app/api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@
1818
async def swagger_ui_html():
1919
return get_swagger_ui_html(openapi_url="/openapi.json", title="LinuxServer API", swagger_favicon_url="/static/logo.png")
2020

21+
async def get_status():
22+
with KeyValueStore() as kv:
23+
return kv["status"]
24+
2125
@api.get("/health", summary="Get the health status")
2226
async def health():
23-
return "Success"
27+
try:
28+
content = await get_status()
29+
return JSONResponse(content=content)
30+
except Exception:
31+
print(traceback.format_exc())
32+
raise HTTPException(status_code=404, detail="Not found")
2433

2534
async def get_images():
2635
with KeyValueStore() as kv:

root/app/updater.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,14 @@ def update_images():
224224

225225
def get_monthly_pulls():
226226
pulls_map = {}
227-
try:
228-
response = requests.get("https://api.scarf.sh/v2/packages/linuxserver-ci/overview?per_page=1000", headers={"Authorization": f"Bearer {SCARF_TOKEN}"})
229-
results = response.json()["results"]
230-
for result in results:
231-
name = result["package"]["name"].replace("linuxserver/", "")
232-
if "total_installs" not in result:
233-
continue
234-
monthly_pulls = result["total_installs"]
235-
pulls_map[name] = monthly_pulls
236-
except Exception:
237-
print(traceback.format_exc())
227+
response = requests.get("https://api.scarf.sh/v2/packages/linuxserver-ci/overview?per_page=1000", headers={"Authorization": f"Bearer {SCARF_TOKEN}"})
228+
results = response.json()["results"]
229+
for result in results:
230+
name = result["package"]["name"].replace("linuxserver/", "")
231+
if "total_installs" not in result:
232+
continue
233+
monthly_pulls = result["total_installs"]
234+
pulls_map[name] = monthly_pulls
238235
return pulls_map
239236

240237
def update_scarf():
@@ -250,15 +247,26 @@ def update_scarf():
250247
new_state = json.dumps(pulls_map)
251248
kv.set_value("scarf", new_state, SCARF_SCHEMA_VERSION)
252249
print(f"{datetime.datetime.now()} - updated scarf")
253-
250+
251+
def update_status(status):
252+
with KeyValueStore(invalidate_hours=0, readonly=False) as kv:
253+
print(f"{datetime.datetime.now()} - updating status")
254+
kv.set_value("status", status, 0)
255+
print(f"{datetime.datetime.now()} - updated status")
254256

255257
def main():
256-
set_db_schema()
257-
while True:
258-
gh.print_rate_limit()
259-
update_scarf()
260-
update_images()
261-
gh.print_rate_limit()
258+
try:
259+
set_db_schema()
260+
while True:
261+
gh.print_rate_limit()
262+
update_scarf()
263+
update_images()
264+
gh.print_rate_limit()
265+
update_status("Success")
266+
time.sleep(INVALIDATE_HOURS*60*60)
267+
except:
268+
print(traceback.format_exc())
269+
update_status("Failed")
262270
time.sleep(INVALIDATE_HOURS*60*60)
263271

264272
if __name__ == "__main__":

0 commit comments

Comments
 (0)