Skip to content

Commit c04ab4d

Browse files
authored
Merge pull request #15 from tblanarik/tblanarik/table-cleanup
Error handling and stubbing out table cleanup methods
2 parents c189a53 + 7c4e216 commit c04ab4d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

cleanup.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import logging
2+
3+
def cleanup():
4+
logging.info("Executing table cleanup function")

function_app.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
import logging
12
import azure.functions as func
23
import spotbot as sb
4+
import cleanup
35

46
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
57

68
@app.route(route="spotbot", methods=[func.HttpMethod.POST])
79
def spotbot(req: func.HttpRequest) -> func.HttpResponse:
8-
sb.run(req)
9-
return func.HttpResponse(status_code=202)
10+
try:
11+
sb.run(req)
12+
except Exception as _excpt:
13+
logging.error(f"Exception occurred: {_excpt}")
14+
return func.HttpResponse(body=f"Exception occurred: {_excpt}", status_code=500)
15+
else:
16+
return func.HttpResponse(status_code=202)
17+
18+
@app.function_name(name="tablecleanup")
19+
@app.schedule(schedule="0 8 * * *",
20+
arg_name="tablecleanup",
21+
run_on_startup=False)
22+
def table_cleanup(timer: func.TimerRequest) -> None:
23+
cleanup.cleanup()
24+
25+
@app.route(route="manualcleanup", methods=[func.HttpMethod.POST])
26+
def manual_cleanup(req: func.HttpRequest) -> func.HttpResponse:
27+
cleanup.cleanup()

0 commit comments

Comments
 (0)