def _set_timeline_status(index_name, status, error_msg=None): """Helper function to set status for searchindex and all related timelines. Args: index_name: Name of the datastore index. status: Status to set. error_msg: Error message. """ # Run within Flask context so we can make database changes with flask_app.app_context(): searchindex = SearchIndex.query.filter_by( index_name=index_name).first() timelines = Timeline.query.filter_by(searchindex=searchindex).all() # Set status searchindex.set_status(status) for timeline in timelines: timeline.set_status(status) db_session.add(timeline) # Update description if there was a failure in ingestion if error_msg and status == u'fail': # TODO: Don't overload the description field. searchindex.description = error_msg # Commit changes to database db_session.add(searchindex) db_session.commit() db_session.remove()
def after_return(self, *args, **kwargs): """Close the database session on task completion.""" db_session.remove() super().after_return(*args, **kwargs)
def tearDown(self): """Tear down the test database.""" db_session.remove() drop_all()
def shutdown_session(exception=None): """Remove the database session after every request or app shutdown.""" db_session.remove()
def after_return(self, *args, **kwargs): """Close the database session on task completion.""" db_session.remove() super(SqlAlchemyTask, self).after_return(*args, **kwargs)