Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Commit ed72537

Browse files
joe1234wufacebook-github-bot
authored andcommitted
Wrap onedocker_svc.get_containers with Throttling Retry (#2219)
Summary: Pull Request resolved: #2219 ## Why onedocker_svc.get_containers might cause Throttling, wrap the retry on it. ## What - Wrap onedocker_svc.get_containers with Throttling Retry Reviewed By: marksliva Differential Revision: D44269329 fbshipit-source-id: 4cb6f2215d477e847abf831f625d78ebff3e0101
1 parent 8db7239 commit ed72537

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

fbpcs/common/entity/stage_state_instance.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
from typing import List, Optional, Union
1313

1414
from fbpcp.entity.container_instance import ContainerInstance, ContainerInstanceStatus
15+
from fbpcp.error.pcp import ThrottlingError
1516
from fbpcp.service.onedocker import OneDockerService
1617
from fbpcp.util.typing import checked_cast
1718
from fbpcs.common.entity.instance_base import InstanceBase
1819
from fbpcs.common.entity.pcs_container_instance import PCSContainerInstance
20+
from fbpcs.common.service.retry_handler import BackoffType, RetryHandler
1921

2022

2123
class StageStateInstanceStatus(Enum):
@@ -88,9 +90,14 @@ def _get_updated_containers(
8890
self, onedocker_svc: OneDockerService
8991
) -> List[ContainerInstance]:
9092
containers_to_update = self.get_containers_to_update(self.containers)
91-
updated_containers = onedocker_svc.get_containers(
92-
[self.containers[idx].instance_id for idx in containers_to_update]
93-
)
93+
with RetryHandler(
94+
ThrottlingError, backoff_type=BackoffType.LINEAR
95+
) as retry_handler:
96+
updated_containers = retry_handler.execute_sync(
97+
onedocker_svc.get_containers,
98+
[self.containers[idx].instance_id for idx in containers_to_update],
99+
)
100+
94101
new_updated_containers = self.containers.copy()
95102
for i, updated_container in zip(containers_to_update, updated_containers):
96103
if updated_container is not None:

fbpcs/private_computation/service/run_binary_base_service.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from fbpcp.entity.container_type import ContainerType
1717
from fbpcp.error.pcp import ThrottlingError
1818
from fbpcp.service.onedocker import OneDockerService
19-
from fbpcs.common.service.retry_handler import RetryHandler
19+
from fbpcs.common.service.retry_handler import BackoffType, RetryHandler
2020
from fbpcs.private_computation.service.constants import DEFAULT_CONTAINER_TIMEOUT_IN_SEC
2121

2222
DEFAULT_WAIT_FOR_CONTAINER_POLL = 5
@@ -145,15 +145,28 @@ async def wait_for_containers_async(
145145
container_ids = [container.instance_id for container in containers]
146146
finished_containers = []
147147

148-
updated_containers = onedocker_svc.get_containers(container_ids)
148+
with RetryHandler(
149+
ThrottlingError, backoff_type=BackoffType.LINEAR
150+
) as retry_handler:
151+
updated_containers = retry_handler.execute_sync(
152+
onedocker_svc.get_containers,
153+
container_ids,
154+
)
149155
pending_container_ids = (
150156
RunBinaryBaseService._remove_finished_containers_from_container_ids(
151157
onedocker_svc, updated_containers, container_ids, finished_containers
152158
)
153159
)
154160
while pending_container_ids:
155161
await asyncio.sleep(poll)
156-
updated_containers = onedocker_svc.get_containers(pending_container_ids)
162+
with RetryHandler(
163+
ThrottlingError, backoff_type=BackoffType.LINEAR
164+
) as retry_handler:
165+
updated_containers = retry_handler.execute_sync(
166+
onedocker_svc.get_containers,
167+
pending_container_ids,
168+
)
169+
157170
pending_container_ids = (
158171
RunBinaryBaseService._remove_finished_containers_from_container_ids(
159172
onedocker_svc,

0 commit comments

Comments
 (0)