Exemplo n.º 1
0
def is_new_user_stats_batch():
    """ Returns True if this batch of user stats is new, False otherwise

    User stats come in as multiple rabbitmq messages. We only wish to send an email once per batch.
    So, we check the database and see if the difference between the last time stats were updated
    and right now is greater than 12 hours.
    """
    return datetime.now(
        timezone.utc) - db_stats.get_timestamp_for_last_user_stats_update(
        ) > timedelta(hours=TIME_TO_CONSIDER_STATS_AS_OLD)
Exemplo n.º 2
0
 def test_get_timestamp_for_last_user_stats_update(self):
     ts = datetime.now(timezone.utc)
     self.insert_test_data()
     received_ts = db_stats.get_timestamp_for_last_user_stats_update()
     self.assertGreaterEqual(received_ts, ts)