Skip to content

Commit 0c0f679

Browse files
feat: Adding 'methodconfig' for all services in channel that allow to retry (#3343)
* feat: Adding 'methodconfig' for all services in channel that allow to retry * chore: adding changelog file 3343.miscellaneous.md --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent c8fb44e commit 0c0f679

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: Adding 'methodconfig' for all services in channel to allow retry

src/ansys/mapdl/core/mapdl_grpc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from functools import wraps
2727
import glob
2828
import io
29+
import json
2930
import os
3031
import pathlib
3132
import re
@@ -117,6 +118,25 @@
117118

118119
SESSION_ID_NAME = "__PYMAPDL_SESSION_ID__"
119120

121+
# Retry policy for gRPC calls.
122+
SERVICE_DEFAULT_CONFIG = {
123+
# see https://github.com/grpc/proposal/blob/master/A6-client-retries.md#retry-policy-capabilities
124+
"methodConfig": [
125+
{
126+
# Match all packages and services.
127+
# Otherwise: "name": [{"service": "<package>.<service>"}],
128+
"name": [{}],
129+
"retryPolicy": {
130+
"maxAttempts": 5,
131+
"initialBackoff": "0.01s",
132+
"maxBackoff": "3s",
133+
"backoffMultiplier": 3,
134+
"retryableStatusCodes": ["UNAVAILABLE", "RESOURCE_EXHAUSTED"],
135+
},
136+
}
137+
]
138+
}
139+
120140

121141
def chunk_raw(raw, save_as):
122142
with io.BytesIO(raw) as f:
@@ -490,6 +510,7 @@ def _create_channel(self, ip: str, port: int) -> grpc.Channel:
490510
channel_str,
491511
options=[
492512
("grpc.max_receive_message_length", MAX_MESSAGE_LENGTH),
513+
("grpc.service_config", json.dumps(SERVICE_DEFAULT_CONFIG)),
493514
],
494515
)
495516

0 commit comments

Comments
 (0)