Skip to content

Commit

Permalink
Add health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinbuss committed Apr 29, 2024
1 parent 23b97ea commit c58e20b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions code/durablefunction/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import azure.durable_functions as df
import azure.functions as func
from models.error import ErrorModel
from models.health import HeartbeatResponse
from models.startworkflow import StartWorkflowRequest
from newstagextraction.orchestration import bp as bp_newstagextraction
from pydantic import ValidationError
Expand Down Expand Up @@ -40,3 +41,13 @@ async def http_start(req: func.HttpRequest, client: df.DurableOrchestrationClien
status_code=422,
)
return response


@app.function_name("Health")
@app.route(route="heartbeat")
@app.http_type(http_type=func.HttpMethod.GET)
async def heartbeat(req: func.HttpRequest) -> func.HttpResponse:
response = HeartbeatResponse(is_alive=True).model_dump_json()
return func.HttpResponse(
body=response, status_code=200, mimetype="application/json"
)
13 changes: 13 additions & 0 deletions code/durablefunction/models/health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pydantic import BaseModel


class HeartbeatResponse(BaseModel):
is_alive: bool = True

@staticmethod
def to_json(obj) -> str:
return obj.model_dump_json()

@staticmethod
def from_json(data: str):
return HeartbeatResponse.model_validate_json(data)

0 comments on commit c58e20b

Please sign in to comment.