From b8a9b8b97f66d3167a97d09b91680e573deca645 Mon Sep 17 00:00:00 2001 From: Mark Vrijlandt Date: Tue, 18 Feb 2025 17:48:44 +0100 Subject: [PATCH 1/2] use new delete_job() from sdk and remove job cancel endpoint --- dev-requirements.txt | 34 ++++++++++++------------- docker-compose.yml | 6 ++--- pyproject.toml | 2 +- requirements.txt | 28 ++++++++++---------- src/omotes_rest/apis/api_dataclasses.py | 11 -------- src/omotes_rest/apis/job.py | 16 +----------- src/omotes_rest/rest_interface.py | 22 +++++----------- 7 files changed, 42 insertions(+), 77 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index dee3d14..64d591b 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.12 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --constraint=requirements.txt --extra=dev --output-file=dev-requirements.txt pyproject.toml @@ -20,11 +20,11 @@ amqp==5.3.1 # via # -c requirements.txt # kombu -apispec[marshmallow]==6.8.0 +apispec[marshmallow]==6.8.1 # via # -c requirements.txt # flask-smorest -attrs==24.2.0 +attrs==25.1.0 # via flake8-bugbear billiard==4.2.1 # via @@ -38,11 +38,11 @@ blinker==1.9.0 # flask build==1.2.2.post1 # via omotes-rest (pyproject.toml) -celery==5.3.6 +celery==5.4.0 # via # -c requirements.txt # omotes-sdk-python -click==8.1.7 +click==8.1.8 # via # -c requirements.txt # black @@ -67,7 +67,7 @@ colorama==0.4.6 # via # -c requirements.txt # omotes-rest (pyproject.toml) -coverage[toml]==7.6.9 +coverage[toml]==7.6.12 # via pytest-cov flake8==7.1.1 # via @@ -131,7 +131,7 @@ itsdangerous==2.2.0 # via # -c requirements.txt # flask -jinja2==3.1.4 +jinja2==3.1.5 # via # -c requirements.txt # flask @@ -139,11 +139,11 @@ kombu==5.4.2 # via # -c requirements.txt # celery -lxml==5.3.0 +lxml==5.3.1 # via # -c requirements.txt # pyecore -mako==1.3.8 +mako==1.3.9 # via # -c requirements.txt # alembic @@ -186,11 +186,11 @@ mypy-extensions==1.0.0 # black # mypy # typing-inspect -omotes-sdk-protocol==0.1.13 +omotes-sdk-protocol==1.0.0 # via # -c requirements.txt # omotes-sdk-python -omotes-sdk-python==3.2.5 +omotes-sdk-python==4.0.1 # via # -c requirements.txt # omotes-rest (pyproject.toml) @@ -220,7 +220,7 @@ platformdirs==4.3.6 # via black pluggy==1.5.0 # via pytest -prompt-toolkit==3.0.48 +prompt-toolkit==3.0.50 # via # -c requirements.txt # click-repl @@ -228,7 +228,7 @@ propcache==0.2.1 # via # -c requirements.txt # yarl -protobuf==4.25.5 +protobuf==5.29.3 # via # -c requirements.txt # omotes-sdk-protocol @@ -266,11 +266,11 @@ python-dotenv==1.0.1 # via # -c requirements.txt # omotes-rest (pyproject.toml) -restrictedpython==7.4 +restrictedpython==8.0 # via # -c requirements.txt # pyecore -setuptools-git-versioning==2.0.0 +setuptools-git-versioning==2.1.0 # via omotes-rest (pyproject.toml) six==1.17.0 # via @@ -296,7 +296,7 @@ types-flask-cors==5.0.0.20240902 # via omotes-rest (pyproject.toml) types-protobuf==4.24.0.20240408 # via omotes-rest (pyproject.toml) -typing-extensions==4.11.0 +typing-extensions==4.12.2 # via # -c requirements.txt # alembic @@ -308,7 +308,7 @@ typing-inspect==0.9.0 # via # -c requirements.txt # marshmallow-dataclass -tzdata==2024.2 +tzdata==2025.1 # via # -c requirements.txt # celery diff --git a/docker-compose.yml b/docker-compose.yml index b32698f..3df3831 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ networks: omotes: external: true -# mapeditor-net: -# external: true + mapeditor-net: + external: true volumes: db-data: @@ -12,7 +12,7 @@ services: image: ghcr.io/project-omotes/omotes_rest:1.1.0 networks: - omotes - #- mapeditor-net + - mapeditor-net ports: - "9200:9200" environment: diff --git a/pyproject.toml b/pyproject.toml index 4037566..4a90cf8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = [ "python-dotenv ~= 1.0.0", "structlog ~= 23.1.0", "SQLAlchemy == 2.0.28", - "omotes-sdk-python ~= 3.2.5", + "omotes-sdk-python ~= 4.0.0", "alembic ~= 1.13.1", ] diff --git a/requirements.txt b/requirements.txt index d5aa944..a8d67f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.12 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --output-file=requirements.txt pyproject.toml @@ -12,15 +12,15 @@ alembic==1.13.3 # via omotes-rest (pyproject.toml) amqp==5.3.1 # via kombu -apispec[marshmallow]==6.8.0 +apispec[marshmallow]==6.8.1 # via flask-smorest billiard==4.2.1 # via celery blinker==1.9.0 # via flask -celery==5.3.6 +celery==5.4.0 # via omotes-sdk-python -click==8.1.7 +click==8.1.8 # via # celery # click-didyoumean @@ -57,13 +57,13 @@ idna==3.10 # via yarl itsdangerous==2.2.0 # via flask -jinja2==3.1.4 +jinja2==3.1.5 # via flask kombu==5.4.2 # via celery -lxml==5.3.0 +lxml==5.3.1 # via pyecore -mako==1.3.8 +mako==1.3.9 # via alembic markupsafe==3.0.2 # via @@ -86,9 +86,9 @@ multidict==6.1.0 # via yarl mypy-extensions==1.0.0 # via typing-inspect -omotes-sdk-protocol==0.1.13 +omotes-sdk-protocol==1.0.0 # via omotes-sdk-python -omotes-sdk-python==3.2.5 +omotes-sdk-python==4.0.1 # via omotes-rest (pyproject.toml) ordered-set==4.1.0 # via pyecore @@ -102,11 +102,11 @@ pamqp==3.3.0 # via # aiormq # omotes-sdk-python -prompt-toolkit==3.0.48 +prompt-toolkit==3.0.50 # via click-repl propcache==0.2.1 # via yarl -protobuf==4.25.5 +protobuf==5.29.3 # via omotes-sdk-protocol psycopg2-binary==2.9.10 # via omotes-rest (pyproject.toml) @@ -118,7 +118,7 @@ python-dateutil==2.9.0.post0 # via celery python-dotenv==1.0.1 # via omotes-rest (pyproject.toml) -restrictedpython==7.4 +restrictedpython==8.0 # via pyecore six==1.17.0 # via python-dateutil @@ -130,7 +130,7 @@ streamcapture==1.2.5 # via omotes-sdk-python structlog==23.1.0 # via omotes-rest (pyproject.toml) -typing-extensions==4.11.0 +typing-extensions==4.12.2 # via # alembic # omotes-sdk-python @@ -138,7 +138,7 @@ typing-extensions==4.11.0 # typing-inspect typing-inspect==0.9.0 # via marshmallow-dataclass -tzdata==2024.2 +tzdata==2025.1 # via # celery # kombu diff --git a/src/omotes_rest/apis/api_dataclasses.py b/src/omotes_rest/apis/api_dataclasses.py index 4de7e70..f35574d 100644 --- a/src/omotes_rest/apis/api_dataclasses.py +++ b/src/omotes_rest/apis/api_dataclasses.py @@ -88,17 +88,6 @@ class JobDeleteResponse: deleted: bool -@add_schema -@dataclass -class JobCancelResponse: - """Response for job cancellation.""" - - Schema: ClassVar[Type[Schema]] = Schema - - job_id: uuid.UUID - cancelled: bool - - @add_schema @dataclass class JobLogsResponse: diff --git a/src/omotes_rest/apis/job.py b/src/omotes_rest/apis/job.py index 0bc5fad..0aa2777 100644 --- a/src/omotes_rest/apis/job.py +++ b/src/omotes_rest/apis/job.py @@ -15,7 +15,6 @@ JobLogsResponse, JobSummary, JobDeleteResponse, - JobCancelResponse, ) from omotes_rest.db_models.job_rest import JobRest from omotes_rest.typed_app import current_app @@ -71,24 +70,11 @@ def get(self, job_id: str) -> JobRest | None: @api.response(200, JobDeleteResponse.Schema()) def delete(self, job_id: str) -> JobDeleteResponse: - """Delete job, and cancel if queued or running.""" + """Delete job: terminate if running, and delete time series data if present.""" job_uuid = uuid.UUID(job_id) return JobDeleteResponse(job_id=job_uuid, deleted=current_app.rest_if.delete_job(job_uuid)) -@api.route("//cancel") -class JobCancelAPI(MethodView): - """Requests.""" - - @api.response(200, JobCancelResponse.Schema()) - def get(self, job_id: str) -> JobCancelResponse: - """Cancel job if queued or running.""" - job_uuid = uuid.UUID(job_id) - return JobCancelResponse( - job_id=job_uuid, cancelled=current_app.rest_if.cancel_job(job_uuid) - ) - - @api.route("//status") class JobStatusAPI(MethodView): """Requests.""" diff --git a/src/omotes_rest/rest_interface.py b/src/omotes_rest/rest_interface.py index aeb70f8..140240d 100644 --- a/src/omotes_rest/rest_interface.py +++ b/src/omotes_rest/rest_interface.py @@ -308,11 +308,11 @@ def get_jobs(self) -> list[JobRest]: """ return self.postgres_if.get_jobs() - def cancel_job(self, job_id: uuid.UUID) -> bool: - """Cancel job by id. + def delete_job(self, job_id: uuid.UUID) -> bool: + """Delete job by id. :param job_id: Job id. - :return: True if job found and cancelled. + :return: True if job found and deleted. """ job_in_db = self.get_job(job_id) @@ -321,22 +321,12 @@ def cancel_job(self, job_id: uuid.UUID) -> bool: job_in_db.workflow_type ) if not workflow_type: - raise RuntimeError(f"Unknown workflow type {job_in_db.workflow_type}") + self.error = RuntimeError(f"Unknown workflow type {job_in_db.workflow_type}") + raise self.error job = Job(id=job_id, workflow_type=workflow_type) - self.omotes_if.cancel_job(job) - result = True - else: - result = False - return result - - def delete_job(self, job_id: uuid.UUID) -> bool: - """Delete job by id. + self.omotes_if.delete_job(job) - :param job_id: Job id. - :return: True if job found and deleted. - """ - self.cancel_job(job_id) return self.postgres_if.delete_job(job_id) def get_job_status(self, job_id: uuid.UUID) -> JobRestStatus | None: From 47ff095d43703197ccec93fc7fffb053060b77f2 Mon Sep 17 00:00:00 2001 From: Mark Vrijlandt Date: Thu, 20 Feb 2025 13:58:20 +0100 Subject: [PATCH 2/2] fix review and use image 1.2.0 --- docker-compose.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3df3831..457f5d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,18 @@ networks: omotes: external: true - mapeditor-net: - external: true +# mapeditor-net: +# external: true volumes: db-data: services: omotes-rest: - image: ghcr.io/project-omotes/omotes_rest:1.1.0 + image: ghcr.io/project-omotes/omotes_rest:1.2.0 networks: - omotes - - mapeditor-net +# - mapeditor-net ports: - "9200:9200" environment: