Ejemplo n.º 1
0
 def get_last_insert_time(self, coll):
     """
     Get datetime object of last insert
     """
     datetime_ = datetime.datetime(1970, 1, 2, 0, 0, 0)
     pipeline = list()
     sort = {'$sort':{'_id':-1}}
     pipeline.append(sort)
     limit = {'$limit':1}
     pipeline.append(limit)
     project = {'$project':{'_id':1}}
     pipeline.append(project)
     for i in range(2):
         try:
             data = self.get_data(coll, pipeline=pipeline)
         except AutoReconnect:
             call(["start_mongodb", self.OPT_PATH])
             continue
         else:
             if data:
                 datetime_ = data[0]['_id'].generation_time
                 datetime_ = datetime_remove_timezone(datetime_)
             else:
                 self.logger.debug('Collection %s is empty, no last insert datetime', coll)
             break
     else:
         self.logger.error("Couldn't establish connection to mongodb server %s", self.URI)
     return datetime_
Ejemplo n.º 2
0
 def test_datetime_remove_timezone(self):
     "Test datetime_remove_timezone function"
     expected = None
     result = datetime_remove_timezone(datetime.datetime.utcnow()).tzinfo
     self.assertEqual(result, expected)
Ejemplo n.º 3
0
 def test_datetime_remove_timezone(self):
     "Test datetime_remove_timezone function"
     expected = None
     result = datetime_remove_timezone(datetime.datetime.utcnow()).tzinfo
     self.assertEqual(result, expected)