예제 #1
0
    def run_once_and_update_timestamp(self):
        # First cover items that have never had a coverage attempt
        # before.
        offset = 0
        while offset is not None:
            offset = self.run_once(
                offset, count_as_covered=BaseCoverageRecord.ALL_STATUSES)

        # Next, cover items that failed with a transient failure
        # on a previous attempt.
        offset = 0
        while offset is not None:
            offset = self.run_once(
                offset,
                count_as_covered=BaseCoverageRecord.DEFAULT_COUNT_AS_COVERED)

        Timestamp.stamp(self._db, self.service_name)
        self._db.commit()
예제 #2
0
    def do_run(self):
        existing_timestamp = get_one(self._db, Timestamp, service=self.name)
        if existing_timestamp:
            raise Exception(
                "Timestamp for Database Migration script already exists")

        migrations = self.fetch_migration_files()[0]
        most_recent_migration = self.sort_migrations(migrations)[-1]

        initial_timestamp = Timestamp.stamp(self._db, self.name)
        self.update_timestamp(initial_timestamp, most_recent_migration)
예제 #3
0
    def test_all(self):
        """Test that we can create a list of Monitors using all()."""
        class OPDSCollectionMonitor(CollectionMonitor):
            SERVICE_NAME = "Test Monitor"
            PROTOCOL = ExternalIntegration.OPDS_IMPORT

        # Here we have three OPDS import Collections...
        o1 = self._collection()
        o2 = self._collection()
        o3 = self._collection()

        # ...and a Bibliotheca collection.
        b1 = self._collection(protocol=ExternalIntegration.BIBLIOTHECA)

        # o1 just had its Monitor run.
        Timestamp.stamp(self._db, OPDSCollectionMonitor.SERVICE_NAME, o1)

        # o2 and b1 have never had their Monitor run, but o2 has had some other Monitor run.
        Timestamp.stamp(self._db, "A Different Service", o2)

        # o3 had its Monitor run an hour ago.
        now = datetime.datetime.utcnow()
        an_hour_ago = now - datetime.timedelta(seconds=3600)
        Timestamp.stamp(self._db, OPDSCollectionMonitor.SERVICE_NAME, o3,
                        an_hour_ago)

        monitors = list(OPDSCollectionMonitor.all(self._db))

        # Three OPDSCollectionMonitors were returned, one for each
        # appropriate collection. The monitor that needs to be run the
        # worst was returned first in the list. The monitor that was
        # run most recently is returned last. There is no
        # OPDSCollectionMonitor for the Bibliotheca collection.
        eq_([o2, o3, o1], [x.collection for x in monitors])
예제 #4
0
    def test_run_starts_at_previous_counter(self):
        # Two Identifiers.
        i1, i2 = [self._identifier() for i in range(2)]

        # The monitor was just run, but it was not able to proceed past
        # i1.
        timestamp = Timestamp.stamp(self._db, self.monitor.service_name,
                                    self.monitor.collection)
        timestamp.counter = i1.id

        # Run the monitor.
        self.monitor.run()

        # The last item in the table was processed. i1 was not
        # processed, because it was processed in a previous run.
        eq_([i2], self.monitor.processed)

        # The monitor's counter has been reset.
        eq_(0, timestamp.counter)
예제 #5
0
 def test_error_not_raised_when_timestamp_forced(self):
     Timestamp.stamp(self._db, self.script.name)
     self.script.do_run(['-f'])
     self.assert_matches_latest_migration()
예제 #6
0
 def test_error_raised_when_timestamp_exists(self):
     Timestamp.stamp(self._db, self.script.name)
     assert_raises(RuntimeError, self.script.do_run)