feat: add main_sync wrapper for asyncio compatibility
All checks were successful
Docker CI/CD / Docker Build and Push to Docker Hub (push) Successful in 10m11s

Refactored the main execution pathway to introduce a `main_sync` function that wraps the existing asynchronous `main` function, facilitating compatibility with environments that necessitate or prefer synchronous execution. This change enhances the bot's flexibility in various deployment scenarios without altering the core asynchronous functionality.

In addition, expanded the exception handling in `get_version` to catch all exceptions instead of limiting to `DistributionNotFound`. This broadens the robustness of version retrieval, ensuring the application can gracefully handle unexpected issues during version lookup.

Whitespace adjustments improve code readability by clearly separating function definitions.

These adjustments contribute to the maintainability and operability of the application, allowing for broader usage contexts and easier integration into diverse environments.
This commit is contained in:
Kumi 2024-05-17 10:58:01 +02:00
parent bc06f8939a
commit 02887b9336
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -7,16 +7,19 @@ import signal
import asyncio
import importlib.metadata
def sigterm_handler(_signo, _stack_frame):
exit()
def get_version():
try:
package_version = importlib.metadata.version("matrix_gptbot")
except pkg_resources.DistributionNotFound:
except Exception:
return None
return package_version
async def main():
# Parse command line arguments
parser = ArgumentParser()
@ -59,5 +62,9 @@ async def main():
print("Received SIGTERM - exiting...")
def main_sync():
asyncio.run(main())
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
main_sync()