Beispiel #1
0
def async_send_scores(message):
    """Send message to all users with active phones and a summary to """
    # Super simple profiling
    start_time = time.time()

    with mail.app.app_context():
        with mail.connect() as conn:
            for user in User.query.filter_by(phone_active=True):
                send_sms(user.carrier, user.phone_num, message, conn=conn)
        num_users = len(User.query.filter_by(phone_active=True).all())

    elapsed_time = time.time() - start_time
    admin_msg = Message(
        "CorpScores Event Stats",
        sender=mail.app.config.get("SMS_DEFAULT_SENDER"),
        recipients=mail.app.config.get("ADMINS"),
    )
    admin_msg.body = """
    Total Users: %d
    Message Length: %d
    Message: %s
    Elapsed time: %f""" % (
        num_users,
        len(message),
        message,
        elapsed_time,
    )
    with mail.app.app_context():
        mail.send(admin_msg)
Beispiel #2
0
 def test_send_sms_with_conn(self, app):
     with mail.record_messages() as outbox:
         with mail.connect() as conn:
             send_sms(carrier='verizon',
                      number=5551112222,
                      message='m' * 300,
                      subject='subject',
                      conn=conn)
         assert len(outbox) is 3
Beispiel #3
0
 def test_send_sms_with_conn(self, app):
     with mail.record_messages() as outbox:
         with mail.connect() as conn:
             send_sms(carrier='verizon',
                      number=5551112222,
                      message='m' * 300,
                      subject='subject',
                      conn=conn)
         assert len(outbox) is 3
Beispiel #4
0
def async_send_scores(message):
    '''Send message to all users with active phones and a summary to '''
    # Super simple profiling
    start_time = time.time()

    with mail.app.app_context():
        with mail.connect() as conn:
            for user in User.query.filter_by(phone_active=True):
                send_sms(user.carrier, user.phone_num, message, conn=conn)
        num_users = len(User.query.filter_by(phone_active=True).all())

    elapsed_time = time.time() - start_time
    admin_msg = Message('CorpScores Event Stats',
                        sender=mail.app.config.get('SMS_DEFAULT_SENDER'),
                        recipients=mail.app.config.get('ADMINS'))
    admin_msg.body = '''
    Total Users: %d
    Message Length: %d
    Message: %s
    Elapsed time: %f''' % (num_users, len(message), message, elapsed_time)
    with mail.app.app_context():
        mail.send(admin_msg)