A simple kafka lambda that interacts with a DB - #440
Merged
tylerharter merged 2 commits intoApr 23, 2026
Merged
Conversation
tylerharter
approved these changes
Apr 23, 2026
tylerharter
left a comment
Member
There was a problem hiding this comment.
Perhaps you can cleanup in a following PR
| if _db_initialized: | ||
| return | ||
| conn = get_db() | ||
| try: |
Member
There was a problem hiding this comment.
I don't love try/finally. Does "with" work on conn? I.e., is conn a "context manager" that can close automatically with used with "with"?
| body = request.get_json(silent=True) | ||
|
|
||
| # Accept {"number": N} | ||
| if isinstance(body, dict): |
Member
There was a problem hiding this comment.
why are we doing these checks? Is any other content valid?
| ensure_db() | ||
|
|
||
| # GET — return current state (useful for checking progress via HTTP) | ||
| if request.method == "GET": |
Member
There was a problem hiding this comment.
why not just make a separate endpoint, and keep this one clean?
| "SELECT last_offset FROM running_sum WHERE id = 1 FOR UPDATE" | ||
| ) | ||
| row = cur.fetchone() | ||
| last_offset = row[0] if row else -1 |
Member
There was a problem hiding this comment.
do we need to check row? does fetchone() raise an exception or just return None when there is no row?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A simple lambda that maintains a running tally of numbers using a local Postgress DB