Skip to content

A simple kafka lambda that interacts with a DB - #440

Merged
tylerharter merged 2 commits into
open-lambda:mainfrom
Yashwanth-Ranjan-Singaravel:feat/simple-db-app
Apr 23, 2026
Merged

A simple kafka lambda that interacts with a DB#440
tylerharter merged 2 commits into
open-lambda:mainfrom
Yashwanth-Ranjan-Singaravel:feat/simple-db-app

Conversation

@Yashwanth-Ranjan-Singaravel

Copy link
Copy Markdown
Contributor

A simple lambda that maintains a running tally of numbers using a local Postgress DB

@tylerharter tylerharter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can cleanup in a following PR

if _db_initialized:
return
conn = get_db()
try:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check row? does fetchone() raise an exception or just return None when there is no row?

@tylerharter
tylerharter merged commit a0273f4 into open-lambda:main Apr 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants