Example #1
0
    def execute(self):
        source_db = PHINMS_DB()
        feeder = Batchfile_Feeder(verbosity=self.verbosity,
                                  source_db=source_db)
        feeder.copy_tempdir = self.copy_tempdir

        while True:
            try:  # long running process, capture interrupt
                if systemUnderLoad():
                    logging.info("system under load - continue anyhow")

                if self.files:
                    # Look up the given files for their filedates
                    self.files = source_db.name_dates(self.files)
                else:
                    self.files = source_db.filelist(self.progression)

                    # If we didn't get any back, we've caught up, take
                    # this opportunity to sleep for a while
                    if self.daemon_mode and not self.files:
                        logging.debug("no files found, sleeping")
                        sleep(5 * 60)

                for batch_file, filedate in self.files:
                    feeder.upload(batch_file, filedate)

                self.files = None  # done with that batch
                if not self.daemon_mode:
                    raise (SystemExit('non daemon-mode exit'))

            except:
                logging.info("Shutting down")
                raise  # now exit
            finally:
                source_db.close()
Example #2
0
    def execute(self):
        source_db = PHINMS_DB()
        feeder = Batchfile_Feeder(verbosity=self.verbosity,
                                  source_db=source_db)
        feeder.copy_tempdir = self.copy_tempdir

        while True:
            try:  # long running process, capture interrupt
                if systemUnderLoad():
                    logging.info("system under load - continue anyhow")

                if self.files:
                    # Look up the given files for their filedates
                    self.files = source_db.name_dates(self.files)
                else:
                    self.files = source_db.filelist(self.progression)

                    # If we didn't get any back, we've caught up, take
                    # this opportunity to sleep for a while
                    if self.daemon_mode and not self.files:
                        logging.debug("no files found, sleeping")
                        sleep(5 * 60)

                for batch_file, filedate in self.files:
                    feeder.upload(batch_file, filedate)

                self.files = None  # done with that batch
                if not self.daemon_mode:
                    raise(SystemExit('non daemon-mode exit'))

            except:
                logging.info("Shutting down")
                raise  # now exit
            finally:
                source_db.close()
Example #3
0
class TestPhinmsDB(unittest.TestCase):
    """Tests for the PHINMS_DB class"""

    def setUp(self):
        super(TestPhinmsDB, self).setUp()
        self.phinms = PHINMS_DB()

    def tearDown(self):
        self.phinms.close()
        super(TestPhinmsDB, self).tearDown()

    def testFeederTable(self):
        "Confirm feeder table exists or can be created"
        self.phinms._create_feeder_table()

        cursor = self.phinms._connect().cursor()
        sql = "SELECT COUNT(*) FROM %s" % self.phinms.feedertable
        cursor.execute(sql)
        result = cursor.fetchone()
        self.assertTrue(int(result[0]) >= 0)

    def test_filelist(self):
        "Confirm query works"
        files = self.phinms.filelist(progression=None)
        self.assertTrue(len(files) <= self.phinms.LIMIT)

    def test_name_dates(self):
        files = 'missing',
        self.assertRaises(ValueError, self.phinms.name_dates, files)