forked from reanahub/reana-workflow-engine-yadage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db: write workflow status to DB instead of FS
* Adds models using plain SQLAlchemy since pallets-eco/flask-sqlalchemy#250 looks like it won't be merged soon. Signed-off-by: Diego Rodriguez <diego.rodriguez@cern.ch>
- Loading branch information
Diego Rodriguez
committed
Oct 19, 2017
1 parent
9256fbc
commit e6340a4
Showing
5 changed files
with
209 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2017 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it under the | ||
# terms of the GNU General Public License as published by the Free Software | ||
# Foundation; either version 2 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# REANA is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# REANA; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | ||
# Suite 330, Boston, MA 02111-1307, USA. | ||
# | ||
# In applying this license, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization or | ||
# submit itself to any jurisdiction. | ||
|
||
"""REANA Workflow Engine Yadage config.""" | ||
|
||
import os | ||
|
||
SHARED_VOLUME = os.getenv('SHARED_VOLUME', '/reana/default') | ||
"""Path to the mounted REANA shared volume.""" | ||
|
||
REANA_DB_FILE = './reana.db' | ||
"""REANA SQLite db file.""" | ||
|
||
SQLALCHEMY_DATABASE_URI = \ | ||
'sqlite:///{SHARED_VOLUME}/{REANA_DB_FILE}'.format( | ||
SHARED_VOLUME=SHARED_VOLUME, | ||
REANA_DB_FILE=REANA_DB_FILE) | ||
"""SQL database URI.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2017 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it under the | ||
# terms of the GNU General Public License as published by the Free Software | ||
# Foundation; either version 2 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# REANA is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# REANA; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | ||
# Suite 330, Boston, MA 02111-1307, USA. | ||
# | ||
# In applying this license, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization or | ||
# submit itself to any jurisdiction. | ||
|
||
"""Rest API endpoint for workflow management.""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from reana_workflow_engine_yadage.config import SQLALCHEMY_DATABASE_URI | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from reana_workflow_engine_yadage.models import User, Workflow # isort:skip # noqa | ||
|
||
|
||
def load_session(): | ||
"""Load SQLAlchemy database session.""" | ||
engine = create_engine(SQLALCHEMY_DATABASE_URI) | ||
Session = sessionmaker(bind=engine) | ||
session = Session() | ||
return session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of REANA. | ||
# Copyright (C) 2017 CERN. | ||
# | ||
# REANA is free software; you can redistribute it and/or modify it under the | ||
# terms of the GNU General Public License as published by the Free Software | ||
# Foundation; either version 2 of the License, or (at your option) any later | ||
# version. | ||
# | ||
# REANA is distributed in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# REANA; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | ||
# Suite 330, Boston, MA 02111-1307, USA. | ||
# | ||
# In applying this license, CERN does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an Intergovernmental Organization or | ||
# submit itself to any jurisdiction. | ||
|
||
"""Models for REANA Workflow Engine Yadage.""" | ||
|
||
from __future__ import absolute_import | ||
|
||
import enum | ||
|
||
from sqlalchemy import Column, DateTime, Enum, ForeignKey, String | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import relationship | ||
from sqlalchemy.sql import func | ||
from sqlalchemy_utils import UUIDType | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class User(Base): | ||
"""User table""" | ||
|
||
__tablename__ = 'user' | ||
|
||
id_ = Column(UUIDType, primary_key=True) | ||
api_key = Column(String(length=120)) | ||
create_date = Column(DateTime, default=func.now()) | ||
email = Column(String(length=255)) | ||
last_active_date = Column(DateTime) | ||
workflows = relationship("Workflow", backref="user") | ||
|
||
def __repr__(self): | ||
"""User string represetantion.""" | ||
return '<User %r>' % self.id_ | ||
|
||
|
||
class WorkflowStatus(enum.Enum): | ||
created = 0 | ||
running = 1 | ||
finished = 2 | ||
failed = 3 | ||
|
||
|
||
class Workflow(Base): | ||
"""Workflow table.""" | ||
|
||
__tablename__ = 'workflow' | ||
|
||
id_ = Column(UUIDType, primary_key=True) | ||
create_date = Column(DateTime, default=func.now()) | ||
workspace_path = Column(String(255)) | ||
status = Column(Enum(WorkflowStatus), default=WorkflowStatus.created) | ||
owner_id = Column(UUIDType, ForeignKey('user.id_')) | ||
|
||
def __repr__(self): | ||
"""Workflow string represetantion.""" | ||
return '<Workflow %r>' % self.id_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters