def insert_element(self, element):
s = db.session
if isinstance(element, DBFeedItem):
try:
s.add(element)
s.commit()
except exc.IntegrityError, e:
# we expect integrity errors. The reason is that we may try to regularly insert the same element into the database
# those elements should not be added to the database and we just rollback the transaction and don't log anything
s.rollback()
except Exception, e:
self._logger.error(str(e))
s.rollback()
elif isinstance(element, Feeditem):
self.insert_element(DBFeedItem(element.content, element.type, element.source, element.time))
else:
self._logger.warning('An element could not be inserted into the database, because it is non of the accepted types. (' + type(element) + ')')
评论列表
文章目录