Skip to content

Commit

Permalink
fix deps
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkTNO committed Mar 18, 2024
1 parent 7a3a777 commit b939b0b
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 220 deletions.
2 changes: 0 additions & 2 deletions .env.docker

This file was deleted.

32 changes: 13 additions & 19 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
POSTGIS_HOST=localhost
POSTGIS_PORT=9232
POSTGIS_DATABASE_NAME=NieuweWarmteNu
POSTGIS_ROOT_USER=root
POSTGIS_ROOT_PASSWORD=1234
RABBITMQ_HOSTNAME=localhost
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=omotes
RABBITMQ_PASSWORD=somepass1
RABBITMQ_VIRTUALHOST=omotes

NWN_POSTGRES_HOST=localhost
NWN_POSTGRES_PORT=6432
NWN_POSTGRES_DATABASE_NAME=nieuwewarmtenu
NWN_POSTGRES_ROOT_USER=root
NWN_POSTGRES_ROOT_PASSWORD=1234

NWN_RABBITMQ_HOST=localhost
NWN_RABBITMQ_PORT=5672
NWN_RABBITMQ_EXCHANGE=nwn
NWN_RABBITMQ_ROOT_USER=root
NWN_RABBITMQ_ROOT_PASSWORD=5678
NWN_RABBITMQ_HIPE_COMPILE=1

#FLASK_APP=src.flask_rest_api.main
POSTGRES_ROOT_USER=root
POSTGRES_ROOT_PASSWORD=1234
POSTGRES_DEV_PORT=7432
POSTGRESQL_HOST=localhost
POSTGRESQL_PORT=7432
POSTGRESQL_DATABASE=omotes
POSTGRESQL_USERNAME=omotes_rest
POSTGRESQL_PASSWORD=somepass3
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.10-slim

ENV ENV=prod
ENV FLASK_APP=tno/mapeditor_dispatcher/main.py
ENV FLASK_APP=src/omotes_rest/main.py

RUN apt-get -y update
RUN pip install --upgrade pip
Expand All @@ -18,4 +18,4 @@ COPY . /code

RUN pip install -e .

CMD gunicorn src.mapeditor_dispatcher.main:app -t 300 -w 1 -b :9200
CMD gunicorn omotes_rest.main:app -t 300 -w 1 -b :9200 --pythonpath src
2 changes: 1 addition & 1 deletion Dockerfile-uwsgi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.8-slim

ENV ENV=prod
ENV FLASK_APP=tno/mapeditor_dispatcher/main.py
ENV FLASK_APP=src/omotes_rest/main.py

RUN apt-get -y update
RUN apt-get install -y gcc libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.infra.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.8"

networks:
omotes:
computation-engine_omotes:

volumes:
db-data:
Expand All @@ -13,7 +13,7 @@ services:
volumes:
- "db-data:/var/lib/postgresql/data/"
networks:
- omotes
- computation-engine_omotes
environment:
PGDATA: /var/lib/postgresql/data
POSTGRES_DB: omotes
Expand All @@ -24,8 +24,8 @@ services:
interval: 5s
timeout: 5s
retries: 10
ports:
- "${POSTGRESQL_PORT}:5432"
# ports:
# - "${POSTGRESQL_PORT}:5432"

# Skipped in 'docker-compose up', only used to develop database revisions.
rest_postgres_db_dev:
Expand All @@ -39,7 +39,7 @@ services:
rest_postgres_db_upgrade:
build: postgres_db_upgrade
networks:
- omotes
- computation-engine_omotes
environment:
POSTGRES_ROOT_USER: ${POSTGRES_ROOT_USER}
POSTGRES_ROOT_PASSWORD: ${POSTGRES_ROOT_PASSWORD}
Expand Down
35 changes: 31 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
version: "3.8"

networks:
computation-engine_omotes:
external: true

volumes:
db-data:

services:
rest_postgres_db:
extends:
file: docker-compose.infra.yml
service: rest_postgres_db

omotes-rest:
build: .
image: mvrijlandt/mapeditor_nwn_dispatcher:0.0.2
# build: .
image: ghcr.io/project-omotes/omotes_rest:0.0.1
networks:
- computation-engine_omotes
ports:
- "9200:9200"
env_file:
- ".env"
environment:
RABBITMQ_HOSTNAME: rabbitmq
RABBITMQ_PORT: 5672
RABBITMQ_USERNAME: ${RABBITMQ_USERNAME}
RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
RABBITMQ_VIRTUALHOST: omotes

POSTGRESQL_HOST: rest_postgres_db
POSTGRESQL_PORT: 5432
POSTGRESQL_DATABASE: omotes
POSTGRESQL_USERNAME: ${POSTGRESQL_USERNAME}
POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
depends_on:
rest_postgres_db:
condition: service_healthy
2 changes: 1 addition & 1 deletion esdl-mapeditor-config/esdl_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# TNO
import os

from src.settings import heatnetwork_dispatcher_config
from settings import heatnetwork_dispatcher_config

EPS_WEB_HOST = os.getenv("EPS_WEB_HOST", "http://epsweb:3401")
ESDL_AGGREGATOR_HOST = os.getenv("ESDL_AGGREGATOR_HOST", "http://esdl-aggregator:3490")
Expand Down
2 changes: 1 addition & 1 deletion postgres_db_upgrade/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# How to work with alembic to make database revisions
The following commands should be run from this folder. (`cd rest_postgres_db_upgrade`)
The following commands should be run from this folder. (`cd postgres_db_upgrade`)

- Setup the virtual environment: `./scripts/create_venv.sh`
- Start postgres in setup mode to expose the port to the host: `./scripts/start_postgres_in_setup_mode.sh`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""initial commit
Revision ID: 50f731d37156
Revision ID: 0b2b6ee9274d
Revises:
Create Date: 2024-03-15 22:14:08.152971
Create Date: 2024-03-18 10:20:54.447282
"""
from typing import Sequence, Union
Expand All @@ -12,7 +12,7 @@


# revision identifiers, used by Alembic.
revision: str = '50f731d37156'
revision: str = '0b2b6ee9274d'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand All @@ -24,7 +24,7 @@ def upgrade() -> None:
sa.Column('job_id', sa.UUID(), nullable=False),
sa.Column('job_name', sa.String(), nullable=False),
sa.Column('work_flow_name', sa.Enum('GROW_OPTIMIZER', 'GROW_SIMULATOR', 'GROW_OPTIMIZER_NO_HEAT_LOSSES', 'GROW_OPTIMIZER_NO_HEAT_LOSSES_DISCOUNTED_CAPEX', 'SIMULATOR', name='workflowname'), nullable=False),
sa.Column('status', sa.Enum('REGISTERED', 'ENQUEUED', 'RUNNING', 'SUCCEEDED', 'CANCELLED', 'TIMEOUT', 'ERROR', name='jobreststatus'), nullable=False),
sa.Column('status', sa.Enum('REGISTERED', 'RUNNING', 'SUCCEEDED', 'CANCELLED', 'TIMEOUT', 'ERROR', name='jobreststatus'), nullable=False),
sa.Column('progress_fraction', sa.Float(), nullable=False),
sa.Column('progress_message', sa.String(), nullable=False),
sa.Column('registered_at', sa.DateTime(timezone=True), nullable=False),
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
"Flask-Cors ~= 4.0.0",
"Flask-DotEnv ~= 0.1.2",
"flask-smorest ~= 0.42.0",
"psycopg2-binary==2.9.3",
"gunicorn ~= 21.2.0",
"marshmallow ~= 3.20.1",
"marshmallow-dataclass ~= 8.5.14",
Expand Down
4 changes: 2 additions & 2 deletions scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

. scripts/_select_docker_compose.sh

$DOCKER_COMPOSE -f ./docker-compose.infra.yml --profile=manual_dev --profile=manual_setup down
$DOCKER_COMPOSE -f ./docker-compose.infra.yml --profile mapeditor-dispatcher up -d
$DOCKER_COMPOSE -f ./docker-compose.yml --profile=manual_dev --profile=manual_setup down
$DOCKER_COMPOSE -f ./docker-compose.yml up -d
4 changes: 2 additions & 2 deletions src/omotes_rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def create_app(object_name):
api.init_app(app)

# Register blueprints.
# from src.omotes_rest.apis.status import api as status_api
from src.omotes_rest.apis.job import api as job_api
# from omotes_rest.apis.status import api as status_api
from omotes_rest.apis.job import api as job_api

# api.register_blueprint(status_api)
api.register_blueprint(job_api)
Expand Down
4 changes: 1 addition & 3 deletions src/omotes_rest/apis/api_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class JobRestStatus(Enum):
this state is not defined in this `Enum`.
"""
REGISTERED = "registered"
"""Job is registered but not yet submitted to Celery."""
ENQUEUED = "enqueued"
"""Job is submitted to Celery but not yet started."""
"""Job is registered but not yet running."""
RUNNING = "running"
"""Job is started and waiting to complete."""
SUCCEEDED = "succeeded"
Expand Down
2 changes: 1 addition & 1 deletion src/omotes_rest/apis/status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# from flask_smorest import Blueprint
# from flask.views import MethodView
# from src.shared.log import get_logger
# from shared.log import get_logger
#
# logger = get_logger("omotes_rest")
#
Expand Down
69 changes: 0 additions & 69 deletions src/omotes_rest/database.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/omotes_rest/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import List, Any
import structlog
from src.omotes_rest.settings import EnvSettings
from omotes_rest.settings import EnvSettings
from structlog.threadlocal import merge_threadlocal

timestamper = structlog.processors.TimeStamper(fmt="iso")
Expand Down
6 changes: 2 additions & 4 deletions src/omotes_rest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from time import strftime

from flask import request, send_from_directory
from src.omotes_rest import create_app
# from src.omotes_rest.database import initialize_db
from src.omotes_rest.settings import EnvSettings
from omotes_rest import create_app
from omotes_rest.settings import EnvSettings

from omotes_rest.log import get_logger
from werkzeug.exceptions import HTTPException
Expand Down Expand Up @@ -81,7 +80,6 @@ def handle_500(e):


def main() -> None:
# initialize_db("nwn")
app.run(
host=EnvSettings.flask_server_host(),
port=EnvSettings.flask_server_port(),
Expand Down
2 changes: 1 addition & 1 deletion src/omotes_rest/omotes_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def handle_on_job_finished(job: Job, result: JobResult) -> None:
postgres_if.set_job_status(
job_id=job.id,
new_status=3, # FINISHED
result_type=result.result_type,
result=result,
)


Expand Down
Loading

0 comments on commit b939b0b

Please sign in to comment.