Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#237): implement app_status_advanced endpoint #238

Merged
merged 6 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ pyrightconfig.json

# Nix
result

4 changes: 4 additions & 0 deletions app/apps/impl/apps_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ async def get_app_status_single(self, app_id: str):
async def get_app_status(self):
raise NotImplementedError()

@abstractmethod
async def get_app_status_advanced(self, app_id: str):
raise NotImplementedError()

@abstractmethod
async def get_app_status_sub(self):
raise NotImplementedError()
Expand Down
3 changes: 3 additions & 0 deletions app/apps/impl/native_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ async def get_app_status_single(self, app_id: str):
async def get_app_status(self):
raise _NotImplemented()

async def get_app_status_advanced(self, app_id: str):
raise _NotImplemented()

async def get_app_status_sub(self):
raise _NotImplemented()

Expand Down
48 changes: 48 additions & 0 deletions app/apps/impl/raspiblitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"mempool",
"thunderhub",
"jam",
"electrs",
}


Expand Down Expand Up @@ -97,6 +98,7 @@ async def get_app_status_single(self, app_id):
"isIndexed": data["isIndexed"],
"indexInfo": data["indexInfo"],
}

return {
"id": app_id,
"version": version,
Expand Down Expand Up @@ -125,6 +127,16 @@ async def get_app_status_single(self, app_id):
"error": f"script result processing error: {script_call}",
}

async def get_app_status_advanced(self, app_id):
if app_id not in available_app_ids:
return {
"id": f"{app_id}",
"error": "appID not in list",
}

if app_id == "electrs":
return _do_electrs_status_advanced()

async def get_app_status(self):
appStatusList: List = []
for appID in available_app_ids:
Expand Down Expand Up @@ -346,3 +358,39 @@ async def run_bonus_script(self, app_id: str, params: str):
logging.debug(f"updatedAppData: {updatedAppData}")
logging.debug(f"params: {params}")
return


async def _do_electrs_status_advanced():
app_id = "electrs"
script_call = (
os.path.join(SHELL_SCRIPT_PATH, "config.scripts", f"bonus.{app_id}.sh")
+ " status"
)

try:
result = await call_sudo_script(script_call)
except:
# script had error or was not able to deliver all requested data fields
logging.warning(f"error on calling: {script_call}")
return {
"id": f"{app_id}",
"error": f"script not working for api: {script_call}",
}

try:
data = parse_key_value_text(result)
except:
logging.warning(f"error on parsing: {result}")
return {
"id": f"{app_id}",
"error": f"script result parsing error: {script_call}",
}

if "initialSynced" not in data:
logging.warning(f"error on calling: {script_call}")
return {
"id": app_id,
"error": f"script not working for api: {script_call}",
}

return {"initialSynced": data["initialSynced"]}
14 changes: 14 additions & 0 deletions app/apps/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ async def get_single_status(id):
return await repo.get_app_status_single(id)


@router.get(
"/status_advanced/{id}",
name=f"{_PREFIX}/status_advanced",
summary="""Get the advanced status of a single app by id.
Some apps might give status information that is computationally to
expensive to include in the normal status endpoint.
""",
dependencies=[Depends(JWTBearer())],
)
@logger.catch(exclude=(HTTPException,))
async def get_single_status_advanced(id):
return await repo.get_app_status_single_advanced(id)


@router.get(
"/status-sub",
name=f"{_PREFIX}/status-sub",
Expand Down
4 changes: 4 additions & 0 deletions app/apps/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ async def get_app_status():
return await apps.get_app_status()


async def get_app_status_advanced(app_id: str):
return await apps.get_app_status_single_advanced(app_id)


async def get_app_status_sub():
return await apps.get_app_status_sub()

Expand Down