Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Added queue for studio processing in PS #2237

Merged
merged 3 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions openpype/hosts/webpublisher/webserver_service/webpublish_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@

class RestApiResource:
"""Resource carrying needed info and Avalon DB connection for publish."""
def __init__(self, server_manager, executable, upload_dir):
def __init__(self, server_manager, executable, upload_dir,
studio_task_queue=None):
self.server_manager = server_manager
self.upload_dir = upload_dir
self.executable = executable

if studio_task_queue is None:
studio_task_queue = collections.deque().dequeu
self.studio_task_queue = studio_task_queue

self.dbcon = AvalonMongoDB()
self.dbcon.install()

Expand Down Expand Up @@ -182,8 +187,6 @@ async def post(self, request) -> Response:
msg = "Non existent OpenPype executable {}".format(openpype_app)
raise RuntimeError(msg)

# for postprocessing in host, currently only PS
output = {}
log.info("WebpublisherBatchPublishEndpoint called")
content = await request.json()

Expand All @@ -203,7 +206,10 @@ async def post(self, request) -> Response:
# would change
# - targets argument is not used in 'remotepublishfromapp'
"targets": None
}
},
# does publish need to be handled by a queue, eg. only
# single process running concurrently?
"add_to_queue": True
}
]

Expand All @@ -219,19 +225,20 @@ async def post(self, request) -> Response:
"targets": ["filespublish"]
}

add_to_queue = False
if content.get("studio_processing"):
log.info("Post processing called")

batch_data = parse_json(os.path.join(batch_path, "manifest.json"))
if not batch_data:
raise ValueError(
"Cannot parse batch meta in {} folder".format(batch_path))
"Cannot parse batch manifest in {}".format(batch_path))
task_dir_name = batch_data["tasks"][0]
task_data = parse_json(os.path.join(batch_path, task_dir_name,
"manifest.json"))
if not task_data:
raise ValueError(
"Cannot parse batch meta in {} folder".format(task_data))
"Cannot parse task manifest in {}".format(task_data))

for process_filter in studio_processing_filters:
filter_extensions = process_filter.get("extensions") or []
Expand All @@ -244,6 +251,7 @@ async def post(self, request) -> Response:
add_args.update(
process_filter.get("arguments") or {}
)
add_to_queue = process_filter["add_to_queue"]
break

args = [
Expand All @@ -263,11 +271,14 @@ async def post(self, request) -> Response:
args.append(value)

log.info("args:: {}".format(args))
if add_to_queue:
log.debug("Adding to queue")
self.resource.studio_task_queue.append(args)
else:
subprocess.call(args)

subprocess.call(args)
return Response(
status=200,
body=self.resource.encode(output),
content_type="application/json"
)

Expand Down
11 changes: 10 additions & 1 deletion openpype/hosts/webpublisher/webserver_service/webserver_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import collections
import time
import os
from datetime import datetime
import requests
import json
import subprocess

from openpype.lib import PypeLogger

Expand Down Expand Up @@ -31,10 +33,13 @@ def run_webserver(*args, **kwargs):
port = kwargs.get("port") or 8079
server_manager = webserver_module.create_new_server_manager(port, host)
webserver_url = server_manager.url
# queue for remotepublishfromapp tasks
studio_task_queue = collections.deque()

resource = RestApiResource(server_manager,
upload_dir=kwargs["upload_dir"],
executable=kwargs["executable"])
executable=kwargs["executable"],
studio_task_queue=studio_task_queue)
projects_endpoint = WebpublisherProjectsEndpoint(resource)
server_manager.add_route(
"GET",
Expand Down Expand Up @@ -88,6 +93,10 @@ def run_webserver(*args, **kwargs):
if time.time() - last_reprocessed > 20:
reprocess_failed(kwargs["upload_dir"], webserver_url)
last_reprocessed = time.time()
if studio_task_queue:
args = studio_task_queue.popleft()
subprocess.call(args) # blocking call

time.sleep(1.0)


Expand Down
3 changes: 1 addition & 2 deletions openpype/settings/defaults/project_settings/photoshop.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
},
"ExtractReview": {
"jpg_options": {
"tags": [
]
"tags": []
},
"mov_options": {
"tags": [
Expand Down