示例#1
0
def export_event_task(self, email, event_id, settings):
    event = safe_query(db, Event, 'id', event_id, 'event_id')
    user = db.session.query(User).filter_by(email=email).first()
    smtp_encryption = get_settings()['smtp_encryption']
    try:
        logging.info('Exporting started')
        path = event_export_task_base(event_id, settings)
        # task_id = self.request.id.__str__()  # str(async result)
        download_url = path

        result = {'download_url': download_url}

        logging.info('Exporting done.. sending email')
        if check_smtp_config(smtp_encryption):
            send_export_mail(email=email,
                             event_name=event.name,
                             download_url=download_url)
        else:
            logging.warning('Error in sending export success email')
        send_notif_after_export(user=user,
                                event_name=event.name,
                                download_url=download_url)
    except Exception as e:
        result = {'__error': True, 'result': str(e)}
        logging.warning('Error in exporting.. sending email')
        if check_smtp_config(smtp_encryption):
            send_export_mail(email=email,
                             event_name=event.name,
                             error_text=str(e))
        else:
            logging.warning('Error in sending export error email')
        send_notif_after_export(user=user,
                                event_name=event.name,
                                error_text=str(e))
    return result
def test_send_notif_after_export(user):
    send_notif_after_export(user, 'Elf Gather', link, 'SLEIGH_BROKEN')
    notification = Notification.query.first()
    assert notification.title == 'Export of event Elf Gather failed'
    assert (
        notification.message
        == 'The following error occurred:<br><pre>SLEIGH_BROKEN</pre>'
    )
示例#3
0
def export_event_task(self, email, event_id, settings):
    event = safe_query(db, Event, 'id', event_id, 'event_id')
    user = db.session.query(User).filter_by(email=email).first()
    try:
        logging.info('Exporting started')
        path = event_export_task_base(event_id, settings)
        # task_id = self.request.id.__str__()  # str(async result)
        download_url = path

        result = {
            'download_url': download_url
        }
        logging.info('Exporting done.. sending email')
        send_export_mail(email=email, event_name=event.name, download_url=download_url)
        send_notif_after_export(user=user, event_name=event.name, download_url=download_url)
    except Exception as e:
        print(traceback.format_exc())
        result = {'__error': True, 'result': str(e)}
        logging.info('Error in exporting.. sending email')
        send_export_mail(email=email, event_name=event.name, error_text=str(e))
        send_notif_after_export(user=user, event_name=event.name, error_text=str(e))

    return result