From 0705e8a7d612d9a59dab01dac2cf1b0ed3c31026 Mon Sep 17 00:00:00 2001 From: Eduardo Robles Elvira Date: Sat, 4 Dec 2021 07:19:18 +0100 Subject: [PATCH] improving logging of contract errors --- authapi/api/models.py | 4 ++-- authapi/api/views.py | 2 +- authapi/authapi/celery.py | 10 ++++++++-- authapi/authapi/settings.py | 8 ++++++-- authapi/authmethods/m_email.py | 2 +- authapi/authmethods/m_email_otp.py | 2 +- authapi/authmethods/m_smart_link.py | 2 +- authapi/authmethods/m_sms.py | 2 +- authapi/authmethods/m_sms_otp.py | 2 +- 9 files changed, 22 insertions(+), 12 deletions(-) diff --git a/authapi/api/models.py b/authapi/api/models.py index 8edd26db..4f867f50 100644 --- a/authapi/api/models.py +++ b/authapi/api/models.py @@ -243,7 +243,7 @@ def children_election_info_validator(value): try: check_contract(CHILDREN_ELECTION_INFO_CONTRACT, value) except CheckException as e: - raise ValidationError(str(e)) + raise ValidationError(str(e.data)) def children_event_id_list_validator(value): if value == None: @@ -252,7 +252,7 @@ def children_event_id_list_validator(value): try: check_contract(CHILDREN_EVENT_ID_LIST_CONTRACT, value) except CheckException as e: - raise ValidationError(str(e)) + raise ValidationError(str(e.data)) class AuthEvent(models.Model): diff --git a/authapi/api/views.py b/authapi/api/views.py index 473fb4a3..17068bae 100644 --- a/authapi/api/views.py +++ b/authapi/api/views.py @@ -2484,7 +2484,7 @@ def post(self, request, pk, ballot_box_pk): "req '%r'\n"\ "error '%r'\n"\ "Stack trace: \n%s",\ - req, error, stack_trace_str()) + req, error.data, stack_trace_str()) return json_response( status=400, error_codename=ErrorCodes.BAD_REQUEST diff --git a/authapi/authapi/celery.py b/authapi/authapi/celery.py index ddc3e9ef..9c7414b5 100644 --- a/authapi/authapi/celery.py +++ b/authapi/authapi/celery.py @@ -1,17 +1,23 @@ import os from celery import Celery +from celery.utils.log import get_task_logger from celery.signals import celeryd_init from django.conf import settings + +logger = get_task_logger(__name__) + @celeryd_init.connect def reset_tallies_task(sender=None, conf=None, **kwargs): ''' Resets the status of the all the AuthEvents with tally pending or started to notstarted. ''' - print('resetting the status of any all the AuthEvents with tally ' + - 'pending or started to notstarted') + logger.info( + 'reset_tallies_task: resetting the status of any all the AuthEvents ' + + 'with tally pending or started to notstarted' + ) from api.models import AuthEvent AuthEvent\ .objects\ diff --git a/authapi/authapi/settings.py b/authapi/authapi/settings.py index ba52c787..5efe7b52 100644 --- a/authapi/authapi/settings.py +++ b/authapi/authapi/settings.py @@ -35,8 +35,12 @@ class CeleryConfig: beat_schedule = { 'review_tallies': { 'task': 'tasks.process_tallies', - 'schedule': timedelta(seconds=5), - 'args': [] + 'schedule': timedelta(seconds=10), + 'args': [], + 'options': { + 'expires': 10 + }, + 'time_limit': 10 }, } result_backend = 'django-db' diff --git a/authapi/authmethods/m_email.py b/authapi/authmethods/m_email.py index 624dab66..99d3a47b 100644 --- a/authapi/authmethods/m_email.py +++ b/authapi/authmethods/m_email.py @@ -289,7 +289,7 @@ def check_config(self, config): "error '%r'\n"\ "config '%r'\n"\ "Stack trace: \n%s",\ - e, config, stack_trace_str()) + e.data, config, stack_trace_str()) return json.dumps(e.data, cls=JsonTypeEncoder) def census(self, auth_event, request): diff --git a/authapi/authmethods/m_email_otp.py b/authapi/authmethods/m_email_otp.py index aac7690c..dcee33e2 100644 --- a/authapi/authmethods/m_email_otp.py +++ b/authapi/authmethods/m_email_otp.py @@ -294,7 +294,7 @@ def check_config(self, config): "error '%r'\n"\ "config '%r'\n"\ "Stack trace: \n%s",\ - e, config, stack_trace_str()) + e.data, config, stack_trace_str()) return json.dumps(e.data, cls=JsonTypeEncoder) def census(self, auth_event, request): diff --git a/authapi/authmethods/m_smart_link.py b/authapi/authmethods/m_smart_link.py index 349af7e8..de23fb6f 100644 --- a/authapi/authmethods/m_smart_link.py +++ b/authapi/authmethods/m_smart_link.py @@ -88,7 +88,7 @@ def check_config(self, config): try: check_contract(self.CONFIG_CONTRACT, config) except CheckException as e: - return str(e) + return str(e.data) return '' def resend_auth_code(self, config): diff --git a/authapi/authmethods/m_sms.py b/authapi/authmethods/m_sms.py index 5dd840de..11fdf191 100644 --- a/authapi/authmethods/m_sms.py +++ b/authapi/authmethods/m_sms.py @@ -294,7 +294,7 @@ def check_config(self, config): "error '%r'\n"\ "config '%r'"\ "Stack trace: \n%s",\ - e, config, stack_trace_str()) + e.data, config, stack_trace_str()) return json.dumps(e.data, cls=JsonTypeEncoder) def census(self, auth_event, request): diff --git a/authapi/authmethods/m_sms_otp.py b/authapi/authmethods/m_sms_otp.py index a57fa4ab..8627af4a 100644 --- a/authapi/authmethods/m_sms_otp.py +++ b/authapi/authmethods/m_sms_otp.py @@ -293,7 +293,7 @@ def check_config(self, config): "error '%r'\n"\ "config '%r'"\ "Stack trace: \n%s",\ - e, config, stack_trace_str()) + e.data, config, stack_trace_str()) return json.dumps(e.data, cls=JsonTypeEncoder) def census(self, auth_event, request):