Exemple #1
0
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()
Exemple #2
0
 def after_return(self, *args, **kwargs):
     """Close the database session on task completion."""
     db_session.remove()
     super().after_return(*args, **kwargs)
Exemple #3
0
 def tearDown(self):
     """Tear down the test database."""
     db_session.remove()
     drop_all()
Exemple #4
0
def shutdown_session(exception=None):
    """Remove the database session after every request or app shutdown."""
    db_session.remove()
Exemple #5
0
 def after_return(self, *args, **kwargs):
     """Close the database session on task completion."""
     db_session.remove()
     super(SqlAlchemyTask, self).after_return(*args, **kwargs)
Exemple #6
0
def shutdown_session(exception=None):
    """Remove the database session after every request or app shutdown."""
    db_session.remove()
Exemple #7
0
 def tearDown(self):
     """Tear down the test database."""
     db_session.remove()
     drop_all()