From 6d3aa3a828ea3655f927fccadb5bcda967e55223 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Thu, 4 Feb 2021 07:37:27 -0800 Subject: [PATCH] Requests: Add `abortOnFail` to ExecuteBatch request We do not currently have atomicy in this request, as it would be incredibly difficult to add, but this is at least useful for avoiding further data corruption in the case that there is a malformed request and multiple requests depend on the success of the previous one. --- src/WSRequestHandler_General.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index ec9bda58..6be43fc8 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -422,7 +422,8 @@ RpcResponse WSRequestHandler::TriggerHotkeyBySequence(const RpcRequest& request) * * @param {Array} `requests` Array of requests to perform. Executed in order. * @param {String} `requests.*.request-type` Request type. Eg. `GetVersion`. -* @param {String} `requests.*.message-id` ID of the individual request. Can be any string and not required to be unique. +* @param {String (Optional)} `requests.*.message-id` ID of the individual request. Can be any string and not required to be unique. Defaults to empty string if not specified. +* @param {boolean (Optional)} `abortOnFail` Stop processing batch requests if one returns a failure. * * @return {Array} `results` Batch requests results, ordered sequentially. * @return {String} `results.*.message-id` ID of the individual request which was originally provided by the client. @@ -439,6 +440,8 @@ RpcResponse WSRequestHandler::ExecuteBatch(const RpcRequest& request) { return request.failed("missing request parameters"); } + bool abortOnFail = obs_data_get_bool(request.parameters(), "abortOnFail"); + OBSDataArrayAutoRelease results = obs_data_array_create(); OBSDataArrayAutoRelease requests = obs_data_get_array(request.parameters(), "requests"); @@ -460,6 +463,10 @@ RpcResponse WSRequestHandler::ExecuteBatch(const RpcRequest& request) { OBSDataAutoRelease subResponseData = OBSRemoteProtocol::rpcResponseToJsonData(subResponse); obs_data_array_push_back(results, subResponseData); + + // if told to abort on fail and a failure occurs, stop request processing and return the progress + if (abortOnFail && (subResponse.status() == RpcResponse::Status::Error)) + break; } OBSDataAutoRelease response = obs_data_create();