Esempio n. 1
0
def user_validator(config):
    subject = config['subject']
    body = config['body']
    sleep_time = config.get('interval', 86400)
    while 1:
        # Sleep first so bouncing notifier doesn't spam
        sleep(sleep_time)
        connection = db.connect()
        cursor = connection.cursor()
        cursor.execute('''SELECT `user`.`name`
                          FROM `event` LEFT JOIN `user_contact` ON `event`.`user_id` = `user_contact`.`user_id`
                              AND `user_contact`.`mode_id` = (SELECT `id` FROM `contact_mode` WHERE `name` = 'call')
                          JOIN `user` ON `event`.`user_id` = `user`.`id`
                          WHERE `event`.`start` > UNIX_TIMESTAMP() AND `user_contact`.`destination` IS NULL
                          GROUP BY `event`.`user_id`;''')
        for row in cursor:
            message = {
                'user': row[0],
                'mode': 'email',
                'subject': subject,
                'body': body
            }
            messengers.send_message(message)
        connection.close()
        cursor.close()
Esempio n. 2
0
def format_and_send_message():
    msg_info = send_queue.get()
    msg = {}
    msg['user'] = msg_info['user']
    msg['mode'] = msg_info['mode']
    context = json_loads(msg_info['context'])
    msg['subject'] = msg_info['subject'] % context
    msg['body'] = msg_info['body'] % context
    try:
        send_message(msg)
    except:
        logger.exception('Failed to send message %s', msg)
        mark_message_as_unsent(msg_info)
        metrics.stats['message_fail_cnt'] += 1
    else:
        mark_message_as_sent(msg_info)
        metrics.stats['message_sent_cnt'] += 1