(params, requests)
| 897 | |
| 898 | |
| 899 | def execute_batch(params, requests): |
| 900 | # type: (KeeperParams, List[dict]) -> List[dict] |
| 901 | responses = [] |
| 902 | if not requests: |
| 903 | return responses |
| 904 | |
| 905 | throttle_delay = 10 |
| 906 | chunk_size = 999 |
| 907 | queue = requests.copy() |
| 908 | delay_next_batch = False |
| 909 | |
| 910 | while len(queue) > 0: |
| 911 | chunk = queue[:chunk_size] |
| 912 | queue = queue[chunk_size:] |
| 913 | |
| 914 | rq = { |
| 915 | 'command': 'execute', |
| 916 | 'requests': chunk |
| 917 | } |
| 918 | try: |
| 919 | if delay_next_batch: |
| 920 | time.sleep(throttle_delay) |
| 921 | rs = communicate(params, rq) |
| 922 | if 'results' in rs: |
| 923 | results = rs['results'] # type: list |
| 924 | if len(results) > 0: |
| 925 | error_rs = results[-1] |
| 926 | throttled = error_rs.get('result') != 'success' and error_rs.get('result_code') == 'throttled' |
| 927 | if throttled: |
| 928 | delay_next_batch = True |
| 929 | results.pop() |
| 930 | responses.extend(results) |
| 931 | |
| 932 | if len(results) < len(chunk): |
| 933 | queue = chunk[len(results):] + queue |
| 934 | except Exception as e: |
| 935 | logging.error(e) |
| 936 | |
| 937 | return responses |
| 938 | |
| 939 | |
| 940 | def update_record(params, record, **kwargs): |
no test coverage detected