This document describes the Azure Functions implemented in src/function_app.py with the Python v2 programming model, which manage a gaming scoreboard system using various Azure services.
The functions demonstrate a complete gaming scoreboard system that uses the following triggers and bindings.
| Trigger Type | Function | Description |
|---|---|---|
| HttpTrigger | GetPlayerScore |
GET endpoint to retrieve player scores: /api/player/{gameId}/{name}/status |
| HttpTrigger | CreateGameStatus |
POST/PUT endpoint for game status requests: /api/game/session |
| BlobTrigger | ProcessGameFile |
Processes uploaded game files from input container |
| QueueTrigger | HandleGameEvent |
Processes game events from input queue |
| QueueTrigger | ProcessScoreboard |
Processes scoreboard data from trigger queue |
| TimerTrigger | CreateGame |
Runs every minute to generate new game rounds |
| Binding Type | Usage | Description |
|---|---|---|
| BlobOutput | ProcessGameFile |
Outputs processed game status to output container |
| QueueOutput | HandleGameEvent |
Sends processed events to output queue |
| TableInput | ProcessScoreboard |
Reads scoreboard entities by game ID |
| TableOutput | ProcessScoreboard |
Writes winner records to winners table |
Function Name: GetPlayerScore
Trigger Type: HTTP GET
Route: /api/player/{gameId}/{name}/status
Description:
Retrieves the score and status for a specific player in a specific game session.
Parameters:
gameId(int) - The game ID to queryname(string) - The player name to look up
Returns:
- HTTP 200: JSON response with PlayerScoreResponse containing player details and score
- HTTP 400: Bad Request if name parameter is missing or invalid
- HTTP 404: Not Found if game/player combination doesn't exist
Example Response:
{
"date": "2025-09-25T10:30:45",
"gameId": 1,
"name": "Leo",
"score": 87
}Function Name: CreateGameStatus
Trigger Type: HTTP POST/PUT
Route: /api/game/session
Description:
Processes game status requests and returns comprehensive game information including winner determination and all player scores.
Request Body:
{
"gameId": 1
}Returns:
- HTTP 200: JSON response with GameStatusResponse containing game details, winner, and all players
- HTTP 400: Bad Request if gameId is missing or invalid
- HTTP 404: Not Found if game doesn't exist
Example Response:
{
"date": "2025-09-25T10:30:45",
"gameId": 1,
"winner": "Paolo",
"players": [
{ "name": "Paolo", "score": 95 },
{ "name": "Leo", "score": 87 },
{ "name": "Mia", "score": 73 }
]
}Function Name: ProcessGameFile
Trigger Type: Blob Trigger
Input Container: %INPUT_STORAGE_CONTAINER_NAME%
Output Container: %OUTPUT_STORAGE_CONTAINER_NAME%
Description:
Automatically processes uploaded game status files from blob storage, deserializes GameStatusRequest objects, and generates comprehensive GameStatusResponse files in the output container.
Input: Blob containing JSON GameStatusRequest
Output: Blob containing JSON GameStatusResponse with winner and player details
Processing Flow:
- Blob uploaded to input container triggers function
- Deserializes GameStatusRequest from blob content
- Retrieves game data from internal dictionary
- Determines winner (highest score)
- Creates GameStatusResponse blob in output container
Function Name: HandleGameEvent
Trigger Type: Queue Trigger
Input Queue: %INPUT_QUEUE_NAME%
Output Queue: %OUTPUT_QUEUE_NAME%
Description:
Processes game events from the input queue, handles GameStatusRequest messages, and generates GameStatusResponse messages for the output queue.
Input: Queue message containing Base64-encoded JSON GameStatusRequest
Output: JSON GameStatusResponse message sent to output queue
Processing Flow:
- Message arrives in input queue
- Deserializes GameStatusRequest from message body
- Looks up game data in internal dictionary
- Determines winner and creates response
- Sends GameStatusResponse to output queue
Function Name: ProcessScoreboard
Trigger Type: Queue Trigger with Table Input
Input Queue: %TRIGGER_QUEUE_NAME%
Input Table: %INPUT_TABLE_NAME%
Output Table: %OUTPUT_TABLE_NAME%
Description:
Processes scoreboard data to determine winners. Retrieves all scoreboard entries for a game, finds the highest scoring player, and records the winner in the output table.
Input:
- Queue message containing gameId
- Table entities matching the gameId from input table
Output: ScoreboardEntity representing the winner stored in output table
Processing Flow:
- Queue message triggers function with gameId
- Queries input table for all players in that game
- Identifies player with highest score
- Creates winner entity in output table
Function Name: CreateGame
Trigger Type: Timer Trigger
Schedule: Every minute (0 */1 * * * *)
Run On Startup: Yes
Description:
Automated function that generates new game rounds with random player data and initiates the complete gaming workflow. This function orchestrates the entire game pipeline.
Operations Performed:
- Infrastructure Initialization: Ensures all Azure Storage components are created
- Game Data Generation: Creates random scores for all configured players
- Internal Storage: Stores game data in memory dictionary for fast access
- Blob Upload: Creates GameStatusRequest blob in input container
- Queue Messages: Sends messages to input and trigger queues
- Table Entries: Creates scoreboard entries for all players
- Workflow Trigger: Initiates the complete processing pipeline
Configuration Dependencies:
PLAYER_NAMES: Comma-separated list of player namesSTORAGE_ACCOUNT_CONNECTION_STRING: Azure Storage connection string- Various queue/container/table name settings
The functions exchange JSON documents, the same ones as the .NET version of the sample:
| Document | Properties | Used by |
|---|---|---|
| Game status request | gameId |
The body of CreateGameStatus, the blobs and the input queue messages |
| Game status response | date, gameId, winner, players (each with name and score) |
The answer of CreateGameStatus, the output blobs and the output messages |
| Player score response | date, gameId, name, score |
The answer of GetPlayerScore |
| Scoreboard entity | PartitionKey (the game id), RowKey, GameId, PlayerName, Score |
The rows of the scoreboards table |
| Winner entity | PartitionKey (winner-game-<game id>), RowKey, GameId, PlayerName, Score |
The rows ProcessScoreboard writes to the winners table |
The application requires the following environment variables/application settings:
| Setting | Description | Default Value |
|---|---|---|
STORAGE_ACCOUNT_CONNECTION_STRING |
Azure Storage connection string | Required |
INPUT_QUEUE_NAME |
Input queue name | input |
OUTPUT_QUEUE_NAME |
Output queue name | output |
TRIGGER_QUEUE_NAME |
Trigger queue name | trigger |
INPUT_STORAGE_CONTAINER_NAME |
Input blob container | input |
OUTPUT_STORAGE_CONTAINER_NAME |
Output blob container | output |
INPUT_TABLE_NAME |
Input table name | scoreboards |
OUTPUT_TABLE_NAME |
Output table name | winners |
PLAYER_NAMES |
Comma-separated player names | Alice,Anastasia,Paolo,Leo,Mia |
- Timer triggers CreateGame: Generates game data and initiates workflow
- Blob uploaded: ProcessGameFile processes the blob
- Queue message sent: HandleGameEvent processes the queue message
- Trigger queue message: ProcessScoreboard determines winner
- HTTP endpoints available: GetPlayerScore and CreateGameStatus provide API access
This creates a complete gaming system with multiple trigger types and processing patterns demonstrating various Azure Functions capabilities.