separated endpoints to those with dbcon and without

This commit is contained in:
Jakub Trllo 2022-06-13 18:20:15 +02:00
parent 444b8aa673
commit 840f1a4314
2 changed files with 25 additions and 17 deletions

View file

@ -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)

View file

@ -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",