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.
This commit is contained in:
tt2468 2021-02-04 07:37:27 -08:00
parent ed23aba0ac
commit 6d3aa3a828

View File

@ -422,7 +422,8 @@ RpcResponse WSRequestHandler::TriggerHotkeyBySequence(const RpcRequest& request)
*
* @param {Array<Object>} `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<Object>} `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();