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 on_message(channel, method_frame, header_frame, body): try: callback(body) except Exception as e: trace = traceback.format_exc() logger.error(trace) try: json_data = json.loads(body.decode("utf-8")) queue_exception = QueueException(queue_name=queue_name, message=json_data, exception_title=type(e).__name__, exception=trace) queue_exception_logger.error(queue_exception.to_exception_log()) except Exception: trace = traceback.format_exc() logger.error(trace) finally: if channel is not None and not channel.is_closed: channel.basic_ack(delivery_tag=method_frame.delivery_tag)
def on_message(channel, method_frame, header_frame, body): try: callback(body) except Exception as e: trace = traceback.format_exc() logger.error(trace) try: json_data = json.loads(body.decode("utf-8")) queue_exception = QueueException( queue_name=queue_name, message=json_data, exception_title=type(e).__name__, exception=trace) queue_exception_logger.error( queue_exception.to_exception_log()) except Exception: trace = traceback.format_exc() logger.error(trace) finally: if channel is not None and not channel.is_closed: channel.basic_ack(delivery_tag=method_frame.delivery_tag)
def fetch_and_save(registration_id, academic_year, acronym): obj = None try: data = fetch_json_data(registration_id, academic_year, acronym) if data: try: obj = save_fetched(registration_id, academic_year, acronym, data) except (PsycopOperationalError, PsycopInterfaceError, DjangoOperationalError, DjangoInterfaceError) as ep: trace = traceback.format_exc() try: data = generate_message(registration_id, academic_year, acronym) queue_exception = QueueException( queue_name=settings.QUEUES.get('QUEUES_NAME').get( 'STUDENT_PERFORMANCE'), 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() obj = save_fetched(registration_id, academic_year, acronym, data) except Exception as e: trace = traceback.format_exc() try: data = generate_message(registration_id, academic_year, acronym) queue_exception = QueueException(queue_name=settings.QUEUES.get( 'QUEUES_NAME').get('STUDENT_PERFORMANCE'), 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)) return obj
def update_exp_date_callback(json_data): try: json_data_dict = json.loads(json_data.decode("utf-8")) registration_id = json_data_dict.get("registrationId") academic_year = json_data_dict.get("academicYear") acronym = json_data_dict.get("acronym") new_exp_date = json_data_dict.get("expirationDate") update_expiration_date(registration_id, academic_year, acronym, new_exp_date) 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( 'PERFORMANCE_UPDATE_EXP_DATE'), 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() update_exp_date_callback(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('PERFORMANCE_UPDATE_EXP_DATE'), message=data, exception_title=type(e).__name__, exception=trace) queue_exception_logger.error(queue_exception.to_exception_log()) except Exception: log_trace = traceback.format_exc() logger.warning( 'Error during queue logging :\n {}'.format(log_trace)) logger.error(trace)
def callback(json_data): try: json_data_dict = json.loads(json_data.decode("utf-8")) registration_id = extract_student_from_json(json_data_dict) academic_year = extract_academic_year_from_json(json_data_dict) acronym = extract_acronym_from_json(json_data_dict) save_consumed(registration_id, academic_year, acronym, json_data_dict) 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( 'PERFORMANCE'), 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() callback(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('PERFORMANCE'), 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 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))