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 Calculation Logic in Task #1275

Draft
wants to merge 1 commit 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
20 changes: 17 additions & 3 deletions src/seer/automation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@
from celery_app.app import celery_app
from seer.db import DbIssueSummary, DbRunState, Session


logger = logging.getLogger(__name__)

def safe_convert_age(age) -> int | None:
if age is None:
return None
try:
return int(age)
except ValueError:
return None

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

for user in user_data:
print(user["age"] * 12) # type: ignore[index]
name = user["name"]
age = safe_convert_age(user["age"])
if age is not None:
yearly_age = age * 12
logger.info(f"User {name}'s yearly age: {yearly_age}")
else:
logger.warning(f"Invalid age for user {name}. Skipping calculation.")


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