diff --git a/openpype/hosts/webpublisher/plugins/publish/collect_batch_data.py b/openpype/hosts/webpublisher/plugins/publish/collect_batch_data.py index a710fcb3e8..062c5ce0da 100644 --- a/openpype/hosts/webpublisher/plugins/publish/collect_batch_data.py +++ b/openpype/hosts/webpublisher/plugins/publish/collect_batch_data.py @@ -12,7 +12,7 @@ from openpype.lib.plugin_tools import ( parse_json, get_batch_asset_task_info ) -from openpype.lib.remote_publish import get_webpublish_conn +from openpype.lib.remote_publish import get_webpublish_conn, IN_PROGRESS_STATUS class CollectBatchData(pyblish.api.ContextPlugin): @@ -74,7 +74,7 @@ class CollectBatchData(pyblish.api.ContextPlugin): dbcon.update_one( { "batch_id": batch_id, - "status": "in_progress" + "status": IN_PROGRESS_STATUS }, { "$set": { diff --git a/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py b/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py index 099819f6ca..cafd651167 100644 --- a/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py +++ b/openpype/hosts/webpublisher/webserver_service/webpublish_routes.py @@ -11,10 +11,14 @@ from avalon.api import AvalonMongoDB from openpype.lib import OpenPypeMongoConnection from openpype_modules.avalon_apps.rest_api import _RestApiEndpoint -from openpype.lib.remote_publish import get_task_data from openpype.settings import get_project_settings from openpype.lib import PypeLogger +from openpype.lib.remote_publish import ( + get_task_data, + ERROR_STATUS, + REPROCESS_STATUS +) log = PypeLogger.get_logger("WebServer") @@ -371,12 +375,12 @@ class BatchReprocessEndpoint(_RestApiEndpoint): """Marks latest 'batch_id' for reprocessing, returns 404 if not found.""" async def post(self, batch_id) -> Response: batches = self.dbcon.find({"batch_id": batch_id, - "status": "error"}).sort("_id", -1) + "status": ERROR_STATUS}).sort("_id", -1) if batches: self.dbcon.update_one( {"_id": batches[0]["_id"]}, - {"$set": {"status": "reprocess"}} + {"$set": {"status": REPROCESS_STATUS}} ) output = [{"msg": "Batch id {} set to reprocess".format(batch_id)}] status = 200 diff --git a/openpype/hosts/webpublisher/webserver_service/webserver_cli.py b/openpype/hosts/webpublisher/webserver_service/webserver_cli.py index 0d0a0223d9..909ea38bc6 100644 --- a/openpype/hosts/webpublisher/webserver_service/webserver_cli.py +++ b/openpype/hosts/webpublisher/webserver_service/webserver_cli.py @@ -20,6 +20,11 @@ from .webpublish_routes import ( TaskPublishEndpoint, UserReportEndpoint ) +from openpype.lib.remote_publish import ( + ERROR_STATUS, + REPROCESS_STATUS, + SENT_REPROCESSING_STATUS +) log = PypeLogger().get_logger("webserver_gui") @@ -125,7 +130,7 @@ def reprocess_failed(upload_dir, webserver_url): database_name = os.environ["OPENPYPE_DATABASE_NAME"] dbcon = mongo_client[database_name]["webpublishes"] - results = dbcon.find({"status": "reprocess"}) + results = dbcon.find({"status": REPROCESS_STATUS}) reprocessed_batches = set() for batch in results: if batch["batch_id"] in reprocessed_batches: @@ -143,7 +148,7 @@ def reprocess_failed(upload_dir, webserver_url): {"$set": { "finish_date": datetime.now(), - "status": "error", + "status": ERROR_STATUS, "progress": 100, "log": batch.get("log") + msg }} @@ -157,12 +162,12 @@ def reprocess_failed(upload_dir, webserver_url): dbcon.update_many( { "batch_id": batch["batch_id"], - "status": {"$in": ["error", "reprocess"]} + "status": {"$in": [ERROR_STATUS, REPROCESS_STATUS]} }, { "$set": { "finish_date": datetime.now(), - "status": "sent_for_reprocessing", + "status": SENT_REPROCESSING_STATUS, "progress": 100 } } diff --git a/openpype/lib/remote_publish.py b/openpype/lib/remote_publish.py index 181802792a..9632e63ea0 100644 --- a/openpype/lib/remote_publish.py +++ b/openpype/lib/remote_publish.py @@ -11,6 +11,13 @@ from openpype import uninstall from openpype.lib.mongo import OpenPypeMongoConnection from openpype.lib.plugin_tools import parse_json +ERROR_STATUS = "error" +IN_PROGRESS_STATUS = "in_progress" +REPROCESS_STATUS = "reprocess" +SENT_REPROCESSING_STATUS = "sent_for_reprocessing" +FINISHED_REPROCESS_STATUS = "republishing_finished" +FINISHED_OK_STATUS = "finished_ok" + def headless_publish(log, close_plugin_name=None, is_test=False): """Runs publish in a opened host with a context and closes Python process. @@ -52,7 +59,7 @@ def start_webpublish_log(dbcon, batch_id, user): "batch_id": batch_id, "start_date": datetime.now(), "user": user, - "status": "in_progress", + "status": IN_PROGRESS_STATUS, "progress": 0 # integer 0-100, percentage }).inserted_id @@ -122,7 +129,7 @@ def publish_and_log(dbcon, _id, log, close_plugin_name=None, batch_id=None): {"$set": { "finish_date": datetime.now(), - "status": "error", + "status": ERROR_STATUS, "log": os.linesep.join(log_lines) }} @@ -146,12 +153,12 @@ def publish_and_log(dbcon, _id, log, close_plugin_name=None, batch_id=None): # final update if batch_id: dbcon.update_many( - {"batch_id": batch_id, "status": "sent_for_reprocessing"}, + {"batch_id": batch_id, "status": SENT_REPROCESSING_STATUS}, { "$set": { "finish_date": datetime.now(), - "status": "republish_finished", + "status": FINISHED_REPROCESS_STATUS, } } ) @@ -162,7 +169,7 @@ def publish_and_log(dbcon, _id, log, close_plugin_name=None, batch_id=None): "$set": { "finish_date": datetime.now(), - "status": "finished_ok", + "status": FINISHED_OK_STATUS, "progress": 100, "log": os.linesep.join(log_lines) } @@ -183,7 +190,7 @@ def fail_batch(_id, batches_in_progress, dbcon): {"$set": { "finish_date": datetime.now(), - "status": "error", + "status": ERROR_STATUS, "log": msg }} diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index 8d0eb773a2..de0336be2b 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -14,7 +14,8 @@ from openpype.lib.remote_publish import ( publish_and_log, fail_batch, find_variant_key, - get_task_data + get_task_data, + IN_PROGRESS_STATUS ) @@ -209,7 +210,7 @@ class PypeCommands: # safer to start logging here, launch might be broken altogether _id = start_webpublish_log(dbcon, batch_id, user_email) - batches_in_progress = list(dbcon.find({"status": "in_progress"})) + batches_in_progress = list(dbcon.find({"status": IN_PROGRESS_STATUS})) if len(batches_in_progress) > 1: fail_batch(_id, batches_in_progress, dbcon) print("Another batch running, probably stuck, ask admin for help")