I am using celery and django-celery-results in my Django application. My celery results are being stored in the backend and this is what celery.py looks like.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shoonya_backend.settings")
# Define celery app and settings
celery_app = Celery(
"shoonya_backend",
result_backend="django-db",
accept_content=["application/json"],
result_serializer="json",
task_serializer="json",
)
celery_app.config_from_object("django.conf:settings", namespace="CELERY")
celery_app.autodiscover_tasks()
I am trying to update the state of a task from within the celery function if I get an exception as follows.
try:
result = resource.import_data(imported_data, raise_errors=True)
# If validation checks fail, raise the Exception
except Exception as e:
self.update_state(
state=states.FAILURE,
meta={
"exc_type": type(e).__name__,
"exc_message": traceback.format_exc().split("\n"),
},
)
The following command doesn't result in any change in the TaskResult table even when the exception is raised and the Task is always a success.