diff --git a/doc/changelog.d/3343.miscellaneous.md b/doc/changelog.d/3343.miscellaneous.md new file mode 100644 index 0000000000..c0dbbed4f1 --- /dev/null +++ b/doc/changelog.d/3343.miscellaneous.md @@ -0,0 +1 @@ +feat: Adding 'methodconfig' for all services in channel to allow retry \ No newline at end of file diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 822d0c0ba6..f6d4442068 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -26,6 +26,7 @@ from functools import wraps import glob import io +import json import os import pathlib import re @@ -117,6 +118,25 @@ SESSION_ID_NAME = "__PYMAPDL_SESSION_ID__" +# Retry policy for gRPC calls. +SERVICE_DEFAULT_CONFIG = { + # see https://github.com/grpc/proposal/blob/master/A6-client-retries.md#retry-policy-capabilities + "methodConfig": [ + { + # Match all packages and services. + # Otherwise: "name": [{"service": "."}], + "name": [{}], + "retryPolicy": { + "maxAttempts": 5, + "initialBackoff": "0.01s", + "maxBackoff": "3s", + "backoffMultiplier": 3, + "retryableStatusCodes": ["UNAVAILABLE", "RESOURCE_EXHAUSTED"], + }, + } + ] +} + def chunk_raw(raw, save_as): with io.BytesIO(raw) as f: @@ -490,6 +510,7 @@ def _create_channel(self, ip: str, port: int) -> grpc.Channel: channel_str, options=[ ("grpc.max_receive_message_length", MAX_MESSAGE_LENGTH), + ("grpc.service_config", json.dumps(SERVICE_DEFAULT_CONFIG)), ], )