(params, requests)
| 872 | |
| 873 | |
| 874 | def execute_batch(params, requests): |
| 875 | # type: (KeeperParams, List[dict]) -> List[dict] |
| 876 | responses = [] |
| 877 | if not requests: |
| 878 | return responses |
| 879 | |
| 880 | throttle_delay = 10 |
| 881 | chunk_size = 999 |
| 882 | queue = requests.copy() |
| 883 | delay_next_batch = False |
| 884 | |
| 885 | while len(queue) > 0: |
| 886 | chunk = queue[:chunk_size] |
| 887 | queue = queue[chunk_size:] |
| 888 | |
| 889 | rq = { |
| 890 | 'command': 'execute', |
| 891 | 'requests': chunk |
| 892 | } |
| 893 | try: |
| 894 | if delay_next_batch: |
| 895 | time.sleep(throttle_delay) |
| 896 | rs = communicate(params, rq) |
| 897 | if 'results' in rs: |
| 898 | results = rs['results'] # type: list |
| 899 | if len(results) > 0: |
| 900 | error_rs = results[-1] |
| 901 | throttled = error_rs.get('result') != 'success' and error_rs.get('result_code') == 'throttled' |
| 902 | if throttled: |
| 903 | delay_next_batch = True |
| 904 | results.pop() |
| 905 | responses.extend(results) |
| 906 | |
| 907 | if len(results) < len(chunk): |
| 908 | queue = chunk[len(results):] + queue |
| 909 | except Exception as e: |
| 910 | logging.error(e) |
| 911 | |
| 912 | return responses |
| 913 | |
| 914 | |
| 915 | def update_record(params, record, **kwargs): |
no test coverage detected