mirror of
https://github.com/linuxserver/docker-lsio-api.git
synced 2026-02-20 08:40:34 +08:00
Update health when the updater fails
This commit is contained in:
parent
af6a726c2f
commit
e151a3a429
@ -18,9 +18,18 @@ api.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
async def swagger_ui_html():
|
||||
return get_swagger_ui_html(openapi_url="/openapi.json", title="LinuxServer API", swagger_favicon_url="/static/logo.png")
|
||||
|
||||
async def get_status():
|
||||
with KeyValueStore() as kv:
|
||||
return kv["status"]
|
||||
|
||||
@api.get("/health", summary="Get the health status")
|
||||
async def health():
|
||||
return "Success"
|
||||
try:
|
||||
content = await get_status()
|
||||
return JSONResponse(content=content)
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
raise HTTPException(status_code=404, detail="Not found")
|
||||
|
||||
async def get_images():
|
||||
with KeyValueStore() as kv:
|
||||
|
||||
@ -224,17 +224,14 @@ def update_images():
|
||||
|
||||
def get_monthly_pulls():
|
||||
pulls_map = {}
|
||||
try:
|
||||
response = requests.get("https://api.scarf.sh/v2/packages/linuxserver-ci/overview?per_page=1000", headers={"Authorization": f"Bearer {SCARF_TOKEN}"})
|
||||
results = response.json()["results"]
|
||||
for result in results:
|
||||
name = result["package"]["name"].replace("linuxserver/", "")
|
||||
if "total_installs" not in result:
|
||||
continue
|
||||
monthly_pulls = result["total_installs"]
|
||||
pulls_map[name] = monthly_pulls
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
response = requests.get("https://api.scarf.sh/v2/packages/linuxserver-ci/overview?per_page=1000", headers={"Authorization": f"Bearer {SCARF_TOKEN}"})
|
||||
results = response.json()["results"]
|
||||
for result in results:
|
||||
name = result["package"]["name"].replace("linuxserver/", "")
|
||||
if "total_installs" not in result:
|
||||
continue
|
||||
monthly_pulls = result["total_installs"]
|
||||
pulls_map[name] = monthly_pulls
|
||||
return pulls_map
|
||||
|
||||
def update_scarf():
|
||||
@ -250,15 +247,26 @@ def update_scarf():
|
||||
new_state = json.dumps(pulls_map)
|
||||
kv.set_value("scarf", new_state, SCARF_SCHEMA_VERSION)
|
||||
print(f"{datetime.datetime.now()} - updated scarf")
|
||||
|
||||
|
||||
def update_status(status):
|
||||
with KeyValueStore(invalidate_hours=0, readonly=False) as kv:
|
||||
print(f"{datetime.datetime.now()} - updating status")
|
||||
kv.set_value("status", status, 0)
|
||||
print(f"{datetime.datetime.now()} - updated status")
|
||||
|
||||
def main():
|
||||
set_db_schema()
|
||||
while True:
|
||||
gh.print_rate_limit()
|
||||
update_scarf()
|
||||
update_images()
|
||||
gh.print_rate_limit()
|
||||
try:
|
||||
set_db_schema()
|
||||
while True:
|
||||
gh.print_rate_limit()
|
||||
update_scarf()
|
||||
update_images()
|
||||
gh.print_rate_limit()
|
||||
update_status("Success")
|
||||
time.sleep(INVALIDATE_HOURS*60*60)
|
||||
except:
|
||||
print(traceback.format_exc())
|
||||
update_status("Failed")
|
||||
time.sleep(INVALIDATE_HOURS*60*60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user