Skip to content

Commit

Permalink
Merge pull request #19 from Project-OMOTES/18-work-flow-configuration…
Browse files Browse the repository at this point in the history
…-in-one-location

workflows in one place working
  • Loading branch information
MarkTNO authored Sep 7, 2024
2 parents 762fd3c + 1e29118 commit aa667ce
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 114 deletions.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
OMOTES_ID=omotes-rest

RABBITMQ_HOSTNAME=localhost
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=omotes
Expand Down
44 changes: 22 additions & 22 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --constraint=requirements.txt --extra=dev --output-file=dev-requirements.txt pyproject.toml
#
aio-pika==9.3.1
aio-pika==9.4.2
# via
# -c requirements.txt
# omotes-sdk-python
aiormq==6.7.7
aiormq==6.8.0
# via
# -c requirements.txt
# aio-pika
Expand Down Expand Up @@ -63,6 +63,8 @@ colorama==0.4.6
# omotes-rest (pyproject.toml)
coverage[toml]==7.4.4
# via pytest-cov
exceptiongroup==1.2.1
# via pytest
flake8==6.0.0
# via
# flake8-docstrings
Expand Down Expand Up @@ -121,19 +123,10 @@ kombu==5.3.5
# via
# -c requirements.txt
# celery
mako==1.3.2
# via
# -c requirements.txt
# pdoc3
markdown==3.6
# via
# -c requirements.txt
# pdoc3
markupsafe==2.1.3
# via
# -c requirements.txt
# jinja2
# mako
# werkzeug
marshmallow==3.20.1
# via
Expand Down Expand Up @@ -168,11 +161,11 @@ mypy-extensions==1.0.0
# black
# mypy
# typing-inspect
omotes-sdk-protocol==0.0.8
omotes-sdk-protocol==0.1.1
# via
# -c requirements.txt
# omotes-sdk-python
omotes-sdk-python==0.0.14
omotes-sdk-python==2.0.2
# via
# -c requirements.txt
# omotes-rest (pyproject.toml)
Expand All @@ -186,16 +179,12 @@ packaging==23.1
# pytest
# setuptools-git-versioning
# webargs
pamqp==3.2.1
pamqp==3.3.0
# via
# -c requirements.txt
# aiormq
pathspec==0.12.1
# via black
pdoc3==0.10.0
# via
# -c requirements.txt
# streamcapture
platformdirs==4.2.0
# via black
pluggy==1.4.0
Expand Down Expand Up @@ -246,24 +235,35 @@ sqlalchemy[mypy]==2.0.28
# via
# -c requirements.txt
# omotes-rest (pyproject.toml)
streamcapture==1.2.2
streamcapture==1.2.5
# via
# -c requirements.txt
# omotes-sdk-python
structlog==23.1.0
# via
# -c requirements.txt
# omotes-rest (pyproject.toml)
toml==0.10.2
# via setuptools-git-versioning
tomli==2.0.1
# via black
# via
# black
# build
# coverage
# flake8-pyproject
# mypy
# pyproject-hooks
# pytest
types-flask-cors==4.0.0.20240405
# via omotes-rest (pyproject.toml)
types-protobuf==4.24.0.20240311
# via omotes-rest (pyproject.toml)
typing-extensions==4.7.1
typing-extensions==4.11.0
# via
# -c requirements.txt
# marshmallow-dataclass
# mypy
# omotes-sdk-python
# sqlalchemy
# typing-inspect
typing-inspect==0.9.0
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:

omotes-rest:
# build: .
image: ghcr.io/project-omotes/omotes_rest:0.0.8
image: ghcr.io/project-omotes/omotes_rest:0.0.9
networks:
- omotes
- mapeditor-net
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies = [
"python-dotenv ~= 1.0.0",
"structlog ~= 23.1.0",
"SQLAlchemy == 2.0.28",
"omotes-sdk-python ~= 0.0.14",
"omotes-sdk-python ~= 2.0.2",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -74,7 +74,7 @@ enabled = true

[tool.pytest.ini_options]
addopts = """--cov=omotes_rest --cov-report html --cov-report term-missing \
--cov-fail-under 2"""
--cov-fail-under 40"""

[tool.coverage.run]
source = ["src"]
Expand Down
25 changes: 10 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements.txt pyproject.toml
#
aio-pika==9.3.1
aio-pika==9.4.2
# via omotes-sdk-python
aiormq==6.7.7
aiormq==6.8.0
# via aio-pika
amqp==5.2.0
# via kombu
Expand Down Expand Up @@ -57,14 +57,9 @@ jinja2==3.1.2
# via flask
kombu==5.3.5
# via celery
mako==1.3.2
# via pdoc3
markdown==3.6
# via pdoc3
markupsafe==2.1.3
# via
# jinja2
# mako
# werkzeug
marshmallow==3.20.1
# via
Expand All @@ -82,20 +77,18 @@ multidict==6.0.5
# via yarl
mypy-extensions==1.0.0
# via typing-inspect
omotes-sdk-protocol==0.0.8
omotes-sdk-protocol==0.1.1
# via omotes-sdk-python
omotes-sdk-python==0.0.14
omotes-sdk-python==2.0.2
# via omotes-rest (pyproject.toml)
packaging==23.1
# via
# apispec
# gunicorn
# marshmallow
# webargs
pamqp==3.2.1
pamqp==3.3.0
# via aiormq
pdoc3==0.10.0
# via streamcapture
prompt-toolkit==3.0.43
# via click-repl
protobuf==4.25.3
Expand All @@ -110,12 +103,14 @@ six==1.16.0
# via python-dateutil
sqlalchemy==2.0.28
# via omotes-rest (pyproject.toml)
streamcapture==1.2.2
streamcapture==1.2.5
# via omotes-sdk-python
structlog==23.1.0
# via omotes-rest (pyproject.toml)
typing-extensions==4.7.1
typing-extensions==4.11.0
# via
# marshmallow-dataclass
# omotes-sdk-python
# sqlalchemy
# typing-inspect
typing-inspect==0.9.0
Expand Down
9 changes: 7 additions & 2 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
. .venv/bin/activate
#!/bin/bash

pip-sync requirements.txt
if [[ "$OSTYPE" != "win32" && "$OSTYPE" != "msys" ]]; then
echo "Activating .venv first."
. .venv/bin/activate
fi

pip-sync ./dev-requirements.txt ./requirements.txt
9 changes: 7 additions & 2 deletions scripts/update_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/bin/bash
. .venv/bin/activate
pip-compile -o requirements.txt ./pyproject.toml

if [[ "$OSTYPE" != "win32" && "$OSTYPE" != "msys" ]]; then
. .venv/bin/activate
fi

pip-compile --output-file=requirements.txt pyproject.toml
pip-compile --extra=dev -c requirements.txt --output-file=dev-requirements.txt pyproject.toml
2 changes: 2 additions & 0 deletions src/omotes_rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def create_app(object_name: str) -> Flask:

# Register blueprints.
from omotes_rest.apis.job import api as job_api
from omotes_rest.apis.workflow import api as workflow_api

api.register_blueprint(job_api)
api.register_blueprint(workflow_api)

CORS(app, resources={r"/*": {"origins": "*"}})

Expand Down
12 changes: 12 additions & 0 deletions src/omotes_rest/apis/api_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
from marshmallow_dataclass import add_schema, dataclass


@add_schema
@dataclass
class WorkflowResponse:
"""Response with available workflows."""

Schema: ClassVar[Type[Schema]] = Schema

workflow_type_name: str
workflow_type_description_name: str
workflow_parameters: dict[str, Any] | None


class JobRestStatus(Enum):
"""Possible job status."""

Expand Down
3 changes: 0 additions & 3 deletions src/omotes_rest/apis/job.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
import logging
import uuid

Expand Down Expand Up @@ -103,8 +102,6 @@ def get(self, job_id: str) -> JobResultResponse:
"""Return job result with output ESDL (can be None)."""
job_uuid = uuid.UUID(job_id)
output_esdl = current_app.rest_if.get_job_output_esdl(job_uuid)
if output_esdl:
output_esdl = base64.b64encode(bytes(output_esdl, "utf-8")).decode("utf-8")
return JobResultResponse(job_id=job_uuid, output_esdl=output_esdl)


Expand Down
26 changes: 26 additions & 0 deletions src/omotes_rest/apis/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging

from flask_smorest import Blueprint
from flask.views import MethodView
from flask import jsonify, Response

from omotes_rest.typed_app import current_app


logger = logging.getLogger("omotes_rest")

api = Blueprint(
"Workflow",
"Workflow",
url_prefix="/workflow",
description="Omotes workflows: retrieve the available workflow and their properties",
)


@api.route("/")
class WorkflowAPI(MethodView):
"""Requests."""

def get(self) -> Response:
"""Return a summary of all workflows with parameter jsonforms format."""
return jsonify(current_app.rest_if.get_workflows_jsonforms_format())
2 changes: 1 addition & 1 deletion src/omotes_rest/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os


class POSTGRESConfig:
class PostgresConfig:
"""Retrieve POSTGRES configuration from environment variables."""

host: str
Expand Down
3 changes: 1 addition & 2 deletions src/omotes_rest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from omotes_rest import create_app
from omotes_rest.rest_interface import RestInterface
from omotes_rest.settings import EnvSettings
from omotes_rest.workflows import WORKFLOW_TYPE_MANAGER
from omotes_rest.typed_app import current_app


Expand Down Expand Up @@ -87,7 +86,7 @@ def post_fork(_: Arbiter, __: SyncWorker) -> None:
with app.app_context():
"""current_app is only within the app context"""

current_app.rest_if = RestInterface(WORKFLOW_TYPE_MANAGER)
current_app.rest_if = RestInterface()
"""Interface for this Omotes Rest service."""

current_app.rest_if.start()
Expand Down
8 changes: 4 additions & 4 deletions src/omotes_rest/postgres_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
from omotes_rest.apis.api_dataclasses import JobRestStatus, JobInput
from omotes_rest.db_models.job_rest import JobRest
from omotes_rest.config import POSTGRESConfig
from omotes_rest.config import PostgresConfig

logger = logging.getLogger("omotes_rest")

Expand Down Expand Up @@ -60,7 +60,7 @@ def session_scope(do_expunge: bool = False) -> Generator[SQLSession, None, None]
Session.remove()


def initialize_db(application_name: str, config: POSTGRESConfig) -> Engine:
def initialize_db(application_name: str, config: PostgresConfig) -> Engine:
"""Initialize the database connection by creating the engine.
Also configure the default session maker.
Expand Down Expand Up @@ -112,12 +112,12 @@ class PostgresInterface:
in this interface must set up a Session (scope) separately.
"""

db_config: POSTGRESConfig
db_config: PostgresConfig
"""Configuration on how to connect to the database."""
engine: Engine
"""Engine for starting connections to the database."""

def __init__(self, postgres_config: POSTGRESConfig) -> None:
def __init__(self, postgres_config: PostgresConfig) -> None:
"""Create the PostgreSQL interface."""
self.db_config = postgres_config

Expand Down
Loading

0 comments on commit aa667ce

Please sign in to comment.