Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
Create database tables upon app instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
HACKERMD committed Jun 21, 2017
1 parent 8723d4a commit 0532f69
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tmserver/appfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

import tmlib.models as tm
from tmlib.log import map_logging_verbosity
from tmlib.models.utils import create_db_engine, create_db_session_factory
from tmlib.models.utils import (
create_db_engine, create_db_tables, create_db_session_factory
)

from tmserver.extensions import jwt
from tmserver.serialize import TmJSONEncoder
Expand All @@ -37,7 +39,7 @@
logger = logging.getLogger(__name__)


def get_interrupted_tasks():
def _get_interrupted_tasks():
"""Gets the IDs of all tasks that are not in state ``STOPPED`` or
``TERMINATED``. If tasks are have one of these states at server startup,
they have probably been interrupted by a previous shutdown and need to
Expand Down Expand Up @@ -185,6 +187,7 @@ def _handle_integrity_error(error):

# Create a session scope for interacting with the main database
engine = create_db_engine(cfg.db_master_uri)
create_db_tables(engine)
session_factory = create_db_session_factory()
session_factory.configure(bind=engine)
session = flask_scoped_session(session_factory, app)
Expand All @@ -202,7 +205,7 @@ def _handle_integrity_error(error):
# Restart all jobs that might have been accidentially stopped by
# a server shutdown.
with app.app_context():
task_ids = get_interrupted_tasks()
task_ids = _get_interrupted_tasks()
for tid in task_ids:
task = gc3pie.retrieve_task(tid)
gc3pie.continue_task(task)
Expand Down

0 comments on commit 0532f69

Please sign in to comment.