diff --git a/src/celery_app/tasks.py b/src/celery_app/tasks.py index 65269eb3..b3d23b45 100644 --- a/src/celery_app/tasks.py +++ b/src/celery_app/tasks.py @@ -6,7 +6,7 @@ from celery_app.app import celery_app as celery # noqa: F401 from celery_app.config import CeleryQueues from seer.automation.autofix.tasks import check_and_mark_recent_autofix_runs -from seer.automation.tasks import delete_data_for_ttl, raise_an_exception +from seer.automation.tasks import buggy_code, delete_data_for_ttl from seer.configuration import AppConfig from seer.dependency_injection import inject, injected @@ -28,7 +28,7 @@ def setup_periodic_tasks(sender, config: AppConfig = injected, **kwargs): # TODO remove this task, it's just for testing in prod; throws an error every minute sender.add_periodic_task( crontab(minute="*", hour="*"), - raise_an_exception.signature(kwargs={}, queue=CeleryQueues.DEFAULT), + buggy_code.signature(kwargs={}, queue=CeleryQueues.DEFAULT), name="Intentionally raise an error", ) diff --git a/src/seer/automation/tasks.py b/src/seer/automation/tasks.py index 3e8ceab0..9ceb03d0 100644 --- a/src/seer/automation/tasks.py +++ b/src/seer/automation/tasks.py @@ -11,14 +11,16 @@ @celery_app.task(time_limit=30) -def raise_an_exception(): - import random - - for i in range(10): - random_int = random.randint(0, 2) - - result = 5 / random_int - logger.info(f"Result of 5 divided by {random_int} is {result}") +def buggy_code(): + 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] @celery_app.task(time_limit=30) diff --git a/tests/test_celery.py b/tests/test_celery.py index 994f5743..2e4556ec 100644 --- a/tests/test_celery.py +++ b/tests/test_celery.py @@ -22,7 +22,7 @@ def test_detected_celery_jobs(): "seer.automation.codegen.unittest_step.unittest_task", "seer.automation.tasks.delete_data_for_ttl", "seer.smoke_test.smoke_test", - "seer.automation.tasks.raise_an_exception", # TODO remove this once testing in prod is done + "seer.automation.tasks.buggy_code", # TODO remove this once testing in prod is done ] )