Ejemplo n.º 1
0
 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_timestamps_to_now(self):
     now = datetime.now()
     start = now - timedelta(hours=2)
     expect = [
         start,
         start + timedelta(hours=1),
         start + timedelta(hours=2),
     ]
     timestamps = timestamps_to_now(start, timedelta(hours=1))
     self.assertEqual(expect, list(timestamps))
 def test_timestamps_to_now(self):
     now = datetime.now()
     start = now - timedelta(hours=2)
     expect = [
         start,
         start + timedelta(hours=1),
         start + timedelta(hours=2),
     ]
     timestamps = timestamps_to_now(start, timedelta(hours=1))
     self.assertEqual(expect, list(timestamps))
Ejemplo n.º 4
0
    def days_missed(cls, report, session):
        """
        Examine the past runs of a recurring report
        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)

        # if a report is pending by this point, it means that it should be re-tried
        session.query(ReportStore) \
            .filter(ReportStore.recurrent_parent_id == report.id) \
            .filter(ReportStore.created >= search_from) \
            .filter(ReportStore.status == celery.states.PENDING) \
            .delete()

        completed_days = [
            pr[0] for pr in session.query(ReportStore.created).filter(
                ReportStore.recurrent_parent_id == report.id).filter(
                    ReportStore.created >= search_from).filter(
                        ReportStore.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 sorted(missed_days)
    def days_missed(cls, report, session):
        """
        Examine the past runs of a recurring report
        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)

        # if a report is pending by this point, it means that it should be re-tried
        session.query(ReportStore) \
            .filter(ReportStore.recurrent_parent_id == report.id) \
            .filter(ReportStore.created >= search_from) \
            .filter(ReportStore.status == celery.states.PENDING) \
            .delete()

        completed_days = [pr[0] for pr in session.query(ReportStore.created)
                          .filter(ReportStore.recurrent_parent_id == report.id)
                          .filter(ReportStore.created >= search_from)
                          .filter(ReportStore.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 sorted(missed_days)