Example #1
0
def send_failure_report(user_id):
    user = models.User.get_by_id(user_id)
    errors = [
        json_loads(e) for e in redis_connection.lrange(key(user_id), 0, -1)
    ]

    if errors:
        errors.reverse()
        occurrences = Counter((e.get('id'), e.get('message')) for e in errors)
        unique_errors = {(e.get('id'), e.get('message')): e for e in errors}

        context = {
            'failures': [{
                'id': v.get('id'),
                'name': v.get('name'),
                'failed_at': v.get('failed_at'),
                'failure_reason': v.get('message'),
                'failure_count': occurrences[k],
                'comment': comment_for(v)
            } for k, v in unique_errors.items()],
            'base_url':
            base_url(user.org)
        }

        html = render_template('emails/failures.html', **context)
        text = render_template('emails/failures.txt', **context)
        subject = "Redash failed to execute {} of your scheduled queries".format(
            len(unique_errors.keys()))
        send_mail.delay([user.email], subject, html, text)

    redis_connection.delete(key(user_id))
Example #2
0
def send_failure_report(user_id):
    user = models.User.get_by_id(user_id)
    errors = [
        json_loads(e) for e in redis_connection.lrange(key(user_id), 0, -1)
    ]

    if errors:
        errors.reverse()
        occurrences = Counter((e.get("id"), e.get("message")) for e in errors)
        unique_errors = {(e.get("id"), e.get("message")): e for e in errors}

        context = {
            "failures": [{
                "id": v.get("id"),
                "name": v.get("name"),
                "failed_at": v.get("failed_at"),
                "failure_reason": v.get("message"),
                "failure_count": occurrences[k],
                "comment": comment_for(v),
            } for k, v in unique_errors.items()],
            "base_url":
            base_url(user.org),
        }

        subject = "Redash failed to execute {} of your scheduled queries".format(
            len(unique_errors.keys()))
        html, text = [
            render_template("emails/failures.{}".format(f), context)
            for f in ["html", "txt"]
        ]

        send_mail.delay([user.email], subject, html, text)

    redis_connection.delete(key(user_id))