Changes for page Batch запити
Last modified by Ashterix on 2024/05/16 18:58
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -199,3 +199,43 @@ 199 199 1. **Convenience and efficiency**: Dependent requests allow performing complex operations with minimal effort, ensuring the correct order of request execution. 200 200 2. **Reducing the number of network requests**: All requests are combined into one, reducing network load. 201 201 3. **Flexibility**: The ability to create complex request scenarios without additional settings or changes on the backend. 202 + 203 += How It Works = 204 + 205 +The batch request processing mechanism works asynchronously. 206 + 207 +When receiving an array of requests, the RPC Server creates a queue of [[Symfony Process>>https://symfony.com/doc/current/components/process.html]], i.e., it runs CLI commands that are processed asynchronously. In a while loop, the state of the processes is checked, and if a result is obtained, it is added to the response array. If there is no response before the timeout expires, an error is returned indicating that the request was not processed. 208 + 209 +== Algorithm: == 210 + 211 +* The batch request is split into individual requests, each of which is added to the queue. 212 +* The queue is checked in a loop for the presence of objects. 213 +* For each object in the queue, it is checked whether the process has finished. 214 +* If the process has finished, the result is added to the response array, and the process is removed from the queue. 215 +* If the process has not finished and the timeout has not expired, the loop continues. 216 +* If the timeout expires before receiving the result, an error is returned for that specific request indicating that it was not processed. 217 + 218 +To increase the timeout for a batch request, you can specify an additional service parameter {{code language="none"}}$rpc.timeout{{/code}} in the request parameters, which is the maximum number of seconds to wait for a response from the process. By default, the timeout value is 10 seconds. 219 + 220 +{{code language="json" layout="LINENUMBERS" title="Request"}} 221 +[ 222 + { 223 + "id":"example_1", 224 + "method":"ExampleApi.fastMethod", 225 + "params":{ 226 + "someParam": "someValue" 227 + } 228 + }, 229 + { 230 + "id":"example_2", 231 + "method":"ExampleApi.longMethod", 232 + "params":{ 233 + "someParam": "someValue", 234 + "$rpc.timeout": 30 235 + } 236 + } 237 +] 238 +{{/code}} 239 + 240 +This allows you to adjust the duration of waiting for results for methods that might take longer to execute, which can be important for processing certain requests. 241 +