From 2bb308627411c6c19d200a580465eee1dfab9e86 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 31 Oct 2024 14:04:50 -0700 Subject: [PATCH 1/3] Move build.py to worker module Building should only be done by workers --- .../conda_store_server/_internal/{ => worker}/build.py | 0 conda-store-server/conda_store_server/_internal/worker/tasks.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename conda-store-server/conda_store_server/_internal/{ => worker}/build.py (100%) diff --git a/conda-store-server/conda_store_server/_internal/build.py b/conda-store-server/conda_store_server/_internal/worker/build.py similarity index 100% rename from conda-store-server/conda_store_server/_internal/build.py rename to conda-store-server/conda_store_server/_internal/worker/build.py diff --git a/conda-store-server/conda_store_server/_internal/worker/tasks.py b/conda-store-server/conda_store_server/_internal/worker/tasks.py index 78c9a60d8..3974a19e1 100644 --- a/conda-store-server/conda_store_server/_internal/worker/tasks.py +++ b/conda-store-server/conda_store_server/_internal/worker/tasks.py @@ -17,7 +17,7 @@ from conda_store_server import api from conda_store_server._internal import environment, schema, utils -from conda_store_server._internal.build import ( +from conda_store_server._internal.worker.build import ( build_cleanup, build_conda_docker, build_conda_env_export, From ca1c9a06e42a7d5906d1cb93fb3f997b5835fa37 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 31 Oct 2024 14:41:41 -0700 Subject: [PATCH 2/3] Add tests for marking build status' --- .../tests/_internal/worker/test_build.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 conda-store-server/tests/_internal/worker/test_build.py diff --git a/conda-store-server/tests/_internal/worker/test_build.py b/conda-store-server/tests/_internal/worker/test_build.py new file mode 100644 index 000000000..d9ec5964a --- /dev/null +++ b/conda-store-server/tests/_internal/worker/test_build.py @@ -0,0 +1,42 @@ +# Copyright (c) conda-store development team. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +from conda_store_server._internal.worker import build +from conda_store_server._internal import schema +from conda_store_server import api + + +def test_build_started(db, seed_conda_store): + test_build = api.get_build(db, build_id=4) + assert test_build.status != schema.BuildStatus.BUILDING + build.set_build_started(db, test_build) + test_build = api.get_build(db, build_id=4) + assert test_build.status == schema.BuildStatus.BUILDING + + +def test_build_failed(db, seed_conda_store): + test_build = api.get_build(db, build_id=4) + assert test_build.status != schema.BuildStatus.FAILED + build.set_build_failed(db, test_build) + test_build = api.get_build(db, build_id=4) + assert test_build.status == schema.BuildStatus.FAILED + + +def test_build_canceled(db, seed_conda_store): + test_build = api.get_build(db, build_id=4) + assert test_build.status != schema.BuildStatus.CANCELED + build.set_build_canceled(db, test_build) + test_build = api.get_build(db, build_id=4) + assert test_build.status == schema.BuildStatus.CANCELED + + +def test_build_completed(db, conda_store, seed_conda_store): + test_build = api.get_build(db, build_id=2) + assert test_build.status != schema.BuildStatus.COMPLETED + build.set_build_completed(db, conda_store, test_build) + test_build = api.get_build(db, build_id=2) + assert test_build.status == schema.BuildStatus.COMPLETED + assert test_build.environment.current_build == test_build + build_artifact = api.get_build_artifact(db, 2, str(test_build.build_path(conda_store))) + assert build_artifact is not None From 471ceb779556d3065e6e7acea9b476acd8e863f2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 20:33:55 +0000 Subject: [PATCH 3/3] [pre-commit.ci] Apply automatic pre-commit fixes --- .../conda_store_server/_internal/worker/tasks.py | 2 +- conda-store-server/tests/_internal/worker/test_build.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/conda-store-server/conda_store_server/_internal/worker/tasks.py b/conda-store-server/conda_store_server/_internal/worker/tasks.py index 3974a19e1..e1005e8f8 100644 --- a/conda-store-server/conda_store_server/_internal/worker/tasks.py +++ b/conda-store-server/conda_store_server/_internal/worker/tasks.py @@ -17,6 +17,7 @@ from conda_store_server import api from conda_store_server._internal import environment, schema, utils +from conda_store_server._internal.worker.app import CondaStoreWorker from conda_store_server._internal.worker.build import ( build_cleanup, build_conda_docker, @@ -26,7 +27,6 @@ build_constructor_installer, solve_conda_environment, ) -from conda_store_server._internal.worker.app import CondaStoreWorker @worker_ready.connect diff --git a/conda-store-server/tests/_internal/worker/test_build.py b/conda-store-server/tests/_internal/worker/test_build.py index d9ec5964a..347aac9e5 100644 --- a/conda-store-server/tests/_internal/worker/test_build.py +++ b/conda-store-server/tests/_internal/worker/test_build.py @@ -2,9 +2,9 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -from conda_store_server._internal.worker import build -from conda_store_server._internal import schema from conda_store_server import api +from conda_store_server._internal import schema +from conda_store_server._internal.worker import build def test_build_started(db, seed_conda_store): @@ -38,5 +38,7 @@ def test_build_completed(db, conda_store, seed_conda_store): test_build = api.get_build(db, build_id=2) assert test_build.status == schema.BuildStatus.COMPLETED assert test_build.environment.current_build == test_build - build_artifact = api.get_build_artifact(db, 2, str(test_build.build_path(conda_store))) + build_artifact = api.get_build_artifact( + db, 2, str(test_build.build_path(conda_store)) + ) assert build_artifact is not None