Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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()
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