def days_missed(cls, report, session): """ Examine the past runs of a recurring report, for up to 30 days. Find any missed runs, including today's run. Raise an exception if there are more runs than expected. Parameters: report : the recurring report to examine session : session to the database Returns: An array of datetimes representing the days when the report did not run """ search_from = strip_time(report.created) look_at_most_this_far = to_datetime(thirty_days_ago()) if search_from < look_at_most_this_far: search_from = look_at_most_this_far completed_days = [pr[0] for pr in session.query(PersistentReport.created) .filter(PersistentReport.recurrent_parent_id == report.id) .filter(PersistentReport.created >= search_from) .filter(PersistentReport.status != celery.states.FAILURE) .all()] expected_days = timestamps_to_now(search_from, timedelta(days=1)) missed_days, unexpected_days = diff_datewise(expected_days, completed_days) if len(unexpected_days) > 0: task_logger.warn('Problem with recurrent report id {}'.format(report.id)) task_logger.warn('Completed runs: {}'.format(sorted(completed_days))) task_logger.warn('Unexpected runs: {}'.format(sorted(unexpected_days))) raise Exception('More reports ran than were supposed to') return missed_days
def test_time_is_excluded(self): today = date.today() form = NamespaceEdits(start_date=today) assert_equals(form.start_date.data, to_datetime(today))