Skip to content

Added health_db_adapter endpoint #199

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

Merged
merged 1 commit into from
Jun 18, 2024
Merged

Conversation

IvanZotin
Copy link

/health_db_adapter - This endpoint returns 200 if the service is available and it can connect to db_adapter (e.g., Ignite) and 500 if the service is unavailable or cannot connect to db_adapter

@SyrexMinus
Copy link
Contributor

@IvanZotin IvanZotin force-pushed the main branch 4 times, most recently from e528204 to 97fe70a Compare June 17, 2024 10:07
return self.db_adapter._redis.ping()
except Exception as _:
log("AIORedisAdapter is not alive", level="INFO")
return
Copy link
Contributor

@SyrexMinus SyrexMinus Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return

Python по умолчанию так делает окончанию функции


async def is_alive(self):
try:
await self.db_adapter._sentinel.sentinels()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IvanZotin IvanZotin force-pushed the main branch 3 times, most recently from bdb3a25 to bd21052 Compare June 18, 2024 10:44
status, reason, answer = 200, "OK", "ok"
is_alive = await self.db_adapter.is_alive()
if not is_alive:
status, reason, answer = 500, "ERROR", "db adapter connection error"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай прокинем в reason комментарий из Exception'а из is_alive?

@@ -70,3 +70,9 @@ async def _path_exists(self, path):

async def _on_prepare(self):
pass

async def is_alive(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async def is_alive(self):
async def is_alive(self) -> bool | None:

Давай аннотациями приправим

@IvanZotin IvanZotin force-pushed the main branch 2 times, most recently from 3bf7d54 to e69fa04 Compare June 18, 2024 11:07
try:
await self.connect()
return True
except Exception as _:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except Exception as _:
except Exception:

@IvanZotin IvanZotin force-pushed the main branch 2 times, most recently from 402e40f to cc24cc5 Compare June 18, 2024 11:17
@@ -70,3 +70,9 @@ async def _path_exists(self, path):

async def _on_prepare(self):
pass

async def is_alive(self) -> bool | None:
Copy link
Contributor

@SyrexMinus SyrexMinus Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async def is_alive(self) -> bool | None:
async def is_alive(self) -> Optional[bool]:

+ импорт
Это для поддержки Python 3.9

@SyrexMinus SyrexMinus merged commit 55adb8e into salute-developers:main Jun 18, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants