From 840f1a431490f0dea02b8e5f9990cc8f5451e1f3 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Mon, 13 Jun 2022 18:20:15 +0200 Subject: [PATCH] separated endpoints to those with dbcon and without --- .../webserver_service/webpublish_routes.py | 36 ++++++++++++------- .../webserver_service/webserver_cli.py | 6 ++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py b/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py index cfbb0939b5..b1041bf6cb 100644 --- a/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py +++ b/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py @@ -20,7 +20,6 @@ from openpype.lib.remote_publish import ( ERROR_STATUS, REPROCESS_STATUS ) -from openpype.pipeline import AvalonMongoDB from openpype.settings import get_project_settings from openpype_modules.webserver.base_routes import RestApiEndpoint @@ -32,6 +31,8 @@ class ResourceRestApiEndpoint(RestApiEndpoint): self.resource = resource super(ResourceRestApiEndpoint, self).__init__() + +class WebpublishApiEndpoint(ResourceRestApiEndpoint): @property def dbcon(self): return self.resource.dbcon @@ -49,9 +50,6 @@ class RestApiResource: studio_task_queue = collections.deque().dequeu self.studio_task_queue = studio_task_queue - self.dbcon = AvalonMongoDB() - self.dbcon.install() - @staticmethod def json_dump_handler(value): if isinstance(value, datetime.datetime): @@ -193,7 +191,7 @@ class TaskNode(Node): self["attributes"] = {} -class BatchPublishEndpoint(ResourceRestApiEndpoint): +class BatchPublishEndpoint(WebpublishApiEndpoint): """Triggers headless publishing of batch.""" async def post(self, request) -> Response: # Validate existence of openpype executable @@ -298,7 +296,7 @@ class BatchPublishEndpoint(ResourceRestApiEndpoint): ) -class TaskPublishEndpoint(ResourceRestApiEndpoint): +class TaskPublishEndpoint(WebpublishApiEndpoint): """Prepared endpoint triggered after each task - for future development.""" async def post(self, request) -> Response: return Response( @@ -308,8 +306,12 @@ class TaskPublishEndpoint(ResourceRestApiEndpoint): ) -class BatchStatusEndpoint(ResourceRestApiEndpoint): - """Returns dict with info for batch_id.""" +class BatchStatusEndpoint(WebpublishApiEndpoint): + """Returns dict with info for batch_id. + + Uses 'WebpublishRestApiResource'. + """ + async def get(self, batch_id) -> Response: output = self.dbcon.find_one({"batch_id": batch_id}) @@ -328,8 +330,12 @@ class BatchStatusEndpoint(ResourceRestApiEndpoint): ) -class UserReportEndpoint(ResourceRestApiEndpoint): - """Returns list of dict with batch info for user (email address).""" +class UserReportEndpoint(WebpublishApiEndpoint): + """Returns list of dict with batch info for user (email address). + + Uses 'WebpublishRestApiResource'. + """ + async def get(self, user) -> Response: output = list(self.dbcon.find({"user": user}, projection={"log": False})) @@ -348,7 +354,7 @@ class UserReportEndpoint(ResourceRestApiEndpoint): ) -class ConfiguredExtensionsEndpoint(ResourceRestApiEndpoint): +class ConfiguredExtensionsEndpoint(WebpublishApiEndpoint): """Returns dict of extensions which have mapping to family. Returns: @@ -388,8 +394,12 @@ class ConfiguredExtensionsEndpoint(ResourceRestApiEndpoint): ) -class BatchReprocessEndpoint(ResourceRestApiEndpoint): - """Marks latest 'batch_id' for reprocessing, returns 404 if not found.""" +class BatchReprocessEndpoint(WebpublishApiEndpoint): + """Marks latest 'batch_id' for reprocessing, returns 404 if not found. + + Uses 'WebpublishRestApiResource'. + """ + async def post(self, batch_id) -> Response: batches = self.dbcon.find({"batch_id": batch_id, "status": ERROR_STATUS}).sort("_id", -1) diff --git a/openpype/hosts/webpublisher/webserver_service/webserver_cli.py b/openpype/hosts/webpublisher/webserver_service/webserver_cli.py index f18aac1168..1ed8f22b2c 100644 --- a/openpype/hosts/webpublisher/webserver_service/webserver_cli.py +++ b/openpype/hosts/webpublisher/webserver_service/webserver_cli.py @@ -69,16 +69,14 @@ def run_webserver(*args, **kwargs): ) # triggers publish - webpublisher_task_publish_endpoint = \ - BatchPublishEndpoint(resource) + webpublisher_task_publish_endpoint = BatchPublishEndpoint(resource) server_manager.add_route( "POST", "/api/webpublish/batch", webpublisher_task_publish_endpoint.dispatch ) - webpublisher_batch_publish_endpoint = \ - TaskPublishEndpoint(resource) + webpublisher_batch_publish_endpoint = TaskPublishEndpoint(resource) server_manager.add_route( "POST", "/api/webpublish/task",