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

Error handling and stubbing out table cleanup methods #15

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import logging

def cleanup():
logging.info("Executing table cleanup function")
22 changes: 20 additions & 2 deletions function_app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
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)
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.function_name(name="tablecleanup")
@app.schedule(schedule="0 8 * * *",
arg_name="tablecleanup",
run_on_startup=False)
def table_cleanup(timer: func.TimerRequest) -> None:
cleanup.cleanup()

@app.route(route="manualcleanup", methods=[func.HttpMethod.POST])
def manual_cleanup(req: func.HttpRequest) -> func.HttpResponse:
cleanup.cleanup()
Loading