Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Refactor Age Processing in User Data Task #1257

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/seer/automation/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from typing import List, Dict, Union
import logging

import sentry_sdk
Expand All @@ -7,20 +8,30 @@
from celery_app.app import celery_app
from seer.db import DbIssueSummary, DbRunState, Session


logger = logging.getLogger(__name__)

def safe_multiply_age(age: Union[int, str, None]) -> int:
if age is None:
return 0
try:
return int(age) * 12
except ValueError:
logger.warning(f"Invalid age value: {age}")
return 0

@celery_app.task(time_limit=30)
def buggy_code():
user_data = [
def process_user_ages():
user_data: List[Dict[str, Union[str, int, None]]] = [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": "25"},
{"name": "Bob", "age": 25},
{"name": "Charlie", "age": None},
{"name": "David", "age": 40},
]

for user in user_data:
print(user["age"] * 12) # type: ignore[index]
result = safe_multiply_age(user["age"])
logger.info(f"User {user['name']}: Age in months = {result}")


@celery_app.task(time_limit=30)
Expand Down
Loading