Skip to content

Commit bc4a859

Browse files
Add retry_delay in invoke method
1 parent fba58c5 commit bc4a859

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

pyrogram/methods/advanced/invoke.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async def invoke(
3434
retries: int = Session.MAX_RETRIES,
3535
timeout: float = Session.WAIT_TIMEOUT,
3636
sleep_threshold: float = None,
37+
retry_delay: float = Session.RETRY_DELAY,
3738
business_connection_id: str = None
3839
):
3940
"""Invoke raw Telegram functions.
@@ -54,15 +55,18 @@ async def invoke(
5455
query (``RawFunction``):
5556
The API Schema function filled with proper arguments.
5657
57-
retries (``int``):
58+
retries (``int``, *optional*):
5859
Number of retries.
5960
60-
timeout (``float``):
61+
timeout (``float`, *optional*`):
6162
Timeout in seconds.
6263
63-
sleep_threshold (``float``):
64+
sleep_threshold (``float``, *optional*):
6465
Sleep threshold in seconds.
6566
67+
retry_delay (``float``, *optional*):
68+
Retry delay in seconds on errors.
69+
6670
business_connection_id (``str``, *optional*):
6771
Unique identifier of the business connection.
6872
@@ -92,10 +96,11 @@ async def invoke(
9296
query = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=query)
9397

9498
r = await session.invoke(
95-
query, retries, timeout,
96-
(sleep_threshold
97-
if sleep_threshold is not None
98-
else self.sleep_threshold)
99+
query=query, retries=retries, timeout=timeout,
100+
sleep_threshold=(
101+
sleep_threshold if sleep_threshold is not None else self.sleep_threshold
102+
),
103+
retry_delay=retry_delay
99104
)
100105

101106
await self.fetch_peers(getattr(r, "users", []))

pyrogram/session/session.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ async def invoke(
516516
query: TLObject,
517517
retries: int = MAX_RETRIES,
518518
timeout: float = WAIT_TIMEOUT,
519-
sleep_threshold: float = SLEEP_THRESHOLD
519+
sleep_threshold: float = SLEEP_THRESHOLD,
520+
retry_delay: float = RETRY_DELAY
520521
):
521522
try:
522523
await asyncio.wait_for(self.is_started.wait(), self.WAIT_TIMEOUT)
@@ -554,7 +555,7 @@ async def invoke(
554555
'[%s] Retrying "%s" due to: %s', attempt, query_name, str(e) or repr(e)
555556
)
556557

557-
await asyncio.sleep(self.RETRY_DELAY)
558+
await asyncio.sleep(retry_delay)
558559

559560
raise TimeoutError(f'Failed to invoke "{query_name}" after {retries} retries')
560561

0 commit comments

Comments
 (0)