From 22bcacb35cb9fbde9c59cf00caa464f8e5c9209c Mon Sep 17 00:00:00 2001 From: Trevor Blanarik Date: Sat, 28 Sep 2024 21:03:47 +0000 Subject: [PATCH 1/2] adds new cleanup function and adds exception handling --- cleanup.py | 4 ++++ function_app.py | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 cleanup.py diff --git a/cleanup.py b/cleanup.py new file mode 100644 index 0000000..e4f77a1 --- /dev/null +++ b/cleanup.py @@ -0,0 +1,4 @@ +import logging + +def cleanup(): + logging.info("Executing table cleanup function") \ No newline at end of file diff --git a/function_app.py b/function_app.py index 3f9bc37..d227e0d 100644 --- a/function_app.py +++ b/function_app.py @@ -1,9 +1,20 @@ +import logging import azure.functions as func import spotbot as sb +import cleanup app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION) @app.route(route="spotbot", methods=[func.HttpMethod.POST]) def spotbot(req: func.HttpRequest) -> func.HttpResponse: - sb.run(req) - return func.HttpResponse(status_code=202) \ No newline at end of file + try: + sb.run(req) + except Exception as _excpt: + logging.error(f"Exception occurred: {_excpt}") + return func.HttpResponse(body=f"Exception occurred: {_excpt}", status_code=500) + else: + return func.HttpResponse(status_code=202) + +@app.route(route="manualcleanup", methods=[func.HttpMethod.POST]) +def manual_cleanup(req: func.HttpRequest) -> func.HttpResponse: + cleanup.cleanup() \ No newline at end of file From 5a91bd7ba871761b8d499c9505453cddd72fbb0f Mon Sep 17 00:00:00 2001 From: Trevor Blanarik Date: Sat, 28 Sep 2024 21:04:04 +0000 Subject: [PATCH 2/2] rename --- function_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/function_app.py b/function_app.py index d227e0d..c28873f 100644 --- a/function_app.py +++ b/function_app.py @@ -15,6 +15,6 @@ def spotbot(req: func.HttpRequest) -> func.HttpResponse: else: return func.HttpResponse(status_code=202) -@app.route(route="manualcleanup", methods=[func.HttpMethod.POST]) +@app.route(route="manual_cleanup", methods=[func.HttpMethod.POST]) def manual_cleanup(req: func.HttpRequest) -> func.HttpResponse: cleanup.cleanup() \ No newline at end of file