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))
def get_waiting_in_queue(queue_name): jobs = [] for raw in redis_connection.lrange(queue_name, 0, -1): job = json_loads(raw) try: args = json_loads(job['headers']['argsrepr']) if args.get('query_id') == 'adhoc': args['query_id'] = None except ValueError: args = {} job_row = { 'state': 'waiting_in_queue', 'task_name': job['headers']['task'], 'worker': None, 'worker_pid': None, 'start_time': None, 'task_id': job['headers']['id'], 'queue': job['properties']['delivery_info']['routing_key'] } job_row.update(args) jobs.append(job_row) return jobs
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))
def get_waiting_in_queue(queue_name): jobs = [] for raw in redis_connection.lrange(queue_name, 0, -1): job = json_loads(raw) try: args = json_loads(job["headers"]["argsrepr"]) if args.get("query_id") == "adhoc": args["query_id"] = None except ValueError: args = {} job_row = { "state": "waiting_in_queue", "task_name": job["headers"]["task"], "worker": None, "worker_pid": None, "start_time": None, "task_id": job["headers"]["id"], "queue": job["properties"]["delivery_info"]["routing_key"], } job_row.update(args) jobs.append(job_row) return jobs