Skip to content

Game processing

function_app.py registers one timer with the six-field schedule 0 */15 * * * *: every 15 minutes. The scheduler decides which work is due. No public HTTP function is registered in this application.

From timer to completed game

flowchart TD
    Tick[15-minute invocation] --> Active{Inside active season?}
    Active -->|No| Exit[Return without external work]
    Active -->|Yes| Dry{DRY_RUN enabled?}
    Dry -->|Yes| Exit
    Dry -->|No| Load[Load private season state]
    Load --> Snapshot[Publish changed public pool data]
    Snapshot --> Done{All games completed?}
    Done -->|Yes| Milestones[Check pending halfway and season-end emails]
    Done -->|No| Schedule[Refresh kickoff cache if due]
    Schedule --> Due{Uncompleted game at or after kickoff?}
    Due -->|No| Milestones
    Due -->|Yes| Final{Cached final result or ESPN final?}
    Final -->|No| Half{First half confirmed complete?}
    Half -->|Yes| Notify[Save halftime result and send halftime winner once]
    Half -->|No| Retry[Record check and retry later]
    Notify --> Retry
    Final -->|Yes| Save[Cache scores and winners]
    Save --> Publish[Publish latest results]
    Publish --> Deliver[Claim and submit winner and summary emails]
    Deliver --> Complete[Mark game completed after successful handling]
    Complete --> Milestones
    Retry --> Milestones
    Milestones --> Exit

The active window begins seven days before the first configured game date and ends fourteen days after the last. Outside it, the scheduler returns before accessing storage or ESPN. DRY_RUN=true also exits before state, publishing, or delivery work.

Kickoff and score checks

BehaviorImplementation
Schedule refreshEvery invocation on configured or cached Eastern game dates and during the first 24 hours after kickoff or a known live game; otherwise once per UTC day
Game matchingNFL week, so a moved kickoff can still use the configured squares
First eligible checkAt the refreshed kickoff
Normal retryEach 15-minute invocation until final status
Long delayOnce per UTC day after kickoff + 24 hours unless the last observed status is live
Finished gamesReuse cached final results; completed games need no new score requests
ESPN request limits5-second connection and 25-second read timeouts; up to two GET retries

The worker sends a separate halftime winner notification when ESPN reports STATUS_HALFTIME in a live game, period three or later in a live game, or final status. Two valid quarter scores are required for each team; a second-quarter clock showing zero alone is not enough. A missed halftime poll is recovered in the second half or after the game. Notifications normally follow within 15 minutes of confirmation, subject to feed and delivery availability. ESPN may still correct scores later.

Halftime results and delivery claims are saved privately, independently of final results. Each period has its own delivery key, even when one player wins both. Previously sent combined winner notifications are respected during upgrades; ambiguous legacy claims still require review. The initial confirmed halftime notification is retained rather than resent after a later score correction. Final published results use the latest verified final feed scores.

The website, weekly recap, and season totals still wait for ESPN’s post state. Quarter-one plus quarter-two scores determine halftime; the final total includes overtime. Missing or malformed scores are rejected rather than treated as zero. Schedule refreshes happen before score checks, so same-day kickoff moves are used immediately. A delayed start remains eligible for polling without sending notifications. Moves announced on a non-game day are discovered by the daily refresh; an unexpected move to an earlier non-game day can therefore be missed until that refresh. Unstarted games delayed beyond 24 hours use daily recovery checks until a revised kickoff or live status is discovered.

Winner lookup

For each period, take the last digit of each team’s score. Find those digits in the week’s Ravens and opponent digit lists. Their intersection selects one owned square. A 23–17 score therefore selects Ravens digit 3 and opponent digit 7.

The data model stores Ravens on rows and opponents on columns; the browser transposes that layout to match the printed pool sheet. See pool data.

Publication and email order

sequenceDiagram
    participant Timer as Scheduler
    participant State as Private state
    participant Blob as Public Blob Storage
    participant ACS as Email provider
    Timer->>State: Persist verified final result
    Timer->>Blob: Write latest and daily JSON
    Timer->>State: Save publication marker
    Timer->>State: Claim delivery as sending using ETag
    Timer->>ACS: Submit HTML and plain text
    ACS-->>Timer: Accepted successfully
    Timer->>State: Mark delivery sent
    Timer->>State: Mark game completed after delivery handling

The scheduler also checks the public snapshot’s content hash before game processing. Changes to names, squares, or other public data can refresh the site even when all games are completed. The hash excludes as_of_utc, so an unchanged snapshot does not get rewritten merely because another invocation passed.

After game processing, the scheduler checks season-summary milestones. It also checks them when all games are already completed. Each milestone waits for verified results across its reporting period and uses a separate delivery claim. A failed milestone does not undo completed games or resend their emails; pending milestones are checked again on the next invocation inside the active window. Ambiguous delivery claims still require operator review.

Game-processing errors are logged by operation and exception type. After attempting other eligible games, the invocation fails if any game work failed. The initial state load, snapshot publication, and schedule refresh occur before that per-game error loop; a failure there can stop the invocation earlier.

For delivery claims that remain sending, follow the recovery procedure.