Esempio n. 1
0
def process_message(json_data):
    from osis_common.models import serializable_model
    json_data_dict = json.loads(json_data.decode("utf-8"))
    try:
        body = serializable_model.unwrap_serialization(json_data_dict)
        if body:
            serializable_model.persist(body)
    except (PsycopOperationalError, PsycopInterfaceError, DjangoOperationalError, DjangoInterfaceError) as ep:
        trace = traceback.format_exc()
        try:
            data = json.loads(json_data.decode("utf-8"))
            queue_exception = QueueException(queue_name=settings.QUEUES.get('QUEUES_NAME').get('MIGRATIONS_TO_CONSUME'),
                                             message=data,
                                             exception_title='[Catched and retried] - {}'.format(type(ep).__name__),
                                             exception=trace)
            queue_exception_logger.error(queue_exception.to_exception_log())
        except Exception:
            logger.error(trace)
            log_trace = traceback.format_exc()
            logger.warning('Error during queue logging and retry:\n {}'.format(log_trace))
        connection.close()
        process_message(json_data)
    except Exception as e:
        trace = traceback.format_exc()
        try:
            data = json.loads(json_data.decode("utf-8"))
            queue_exception = QueueException(queue_name=settings.QUEUES.get('QUEUES_NAME').get('MIGRATIONS_TO_CONSUME'),
                                             message=data,
                                             exception_title=type(e).__name__,
                                             exception=trace)
            queue_exception_logger.error(queue_exception.to_exception_log())
        except Exception:
            logger.error(trace)
            log_trace = traceback.format_exc()
            logger.warning('Error during queue logging :\n {}'.format(log_trace))
 def test_persist_case_insert_new_one(self, mock_make_upsert):
     structure_serialized = serialize(self.model_with_user, to_delete=False)
     persist(structure_serialized)
     mock_make_upsert.assert_called_once_with(
         structure_serialized['fields'],
         SerializableModel,
         ModelWithUser
     )
Esempio n. 3
0
    def test_persist_case_update_existing(self, mock_make_upsert):
        # Save instance in order to have UUID on database
        self.model_with_user.save()

        structure_serialized = serialize(self.model_with_user, to_delete=False)
        persist(structure_serialized)
        mock_make_upsert.assert_called_once_with(
            structure_serialized['fields'],
            SerializableModel,
            ModelWithUser,
            instance=self.model_with_user)
    def test_persist_case_update_existing(self, mock_make_upsert):
        # Save instance in order to have UUID on database
        self.model_with_user.save()

        structure_serialized = serialize(self.model_with_user, to_delete=False)
        persist(structure_serialized)
        mock_make_upsert.assert_called_once_with(
            structure_serialized['fields'],
            SerializableModel,
            ModelWithUser,
            instance=self.model_with_user
        )
Esempio n. 5
0
def process_message(json_data):
    from osis_common.models import serializable_model
    json_data_dict = json.loads(json_data.decode("utf-8"))
    try:
        body = serializable_model.unwrap_serialization(json_data_dict)
        if body:
            serializable_model.persist(body)
    except (PsycopOperationalError, PsycopInterfaceError,
            DjangoOperationalError, DjangoInterfaceError) as ep:
        trace = traceback.format_exc()
        try:
            data = json.loads(json_data.decode("utf-8"))
            queue_exception = QueueException(
                queue_name=settings.QUEUES.get('QUEUES_NAME').get(
                    'MIGRATIONS_TO_CONSUME'),
                message=data,
                exception_title='[Catched and retried] - {}'.format(
                    type(ep).__name__),
                exception=trace)
            queue_exception_logger.error(queue_exception.to_exception_log())
        except Exception:
            logger.error(trace)
            log_trace = traceback.format_exc()
            logger.warning(
                'Error during queue logging and retry:\n {}'.format(log_trace))
        connection.close()
        process_message(json_data)
    except Exception as e:
        trace = traceback.format_exc()
        try:
            data = json.loads(json_data.decode("utf-8"))
            queue_exception = QueueException(queue_name=settings.QUEUES.get(
                'QUEUES_NAME').get('MIGRATIONS_TO_CONSUME'),
                                             message=data,
                                             exception_title=type(e).__name__,
                                             exception=trace)
            queue_exception_logger.error(queue_exception.to_exception_log())
        except Exception:
            logger.error(trace)
            log_trace = traceback.format_exc()
            logger.warning(
                'Error during queue logging :\n {}'.format(log_trace))
Esempio n. 6
0
def process_message(json_data):
    from osis_common.models import serializable_model
    data = json.loads(json_data.decode("utf-8"))
    body = serializable_model.unwrap_serialization(data)
    if body:
        serializable_model.persist(body)
Esempio n. 7
0
 def test_persist_case_insert_new_one(self, mock_make_upsert):
     structure_serialized = serialize(self.model_with_user, to_delete=False)
     persist(structure_serialized)
     mock_make_upsert.assert_called_once_with(
         structure_serialized['fields'], SerializableModel, ModelWithUser)