File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ import random
2+
3+ import pytest
4+
5+ from taskiq import (
6+ Context ,
7+ InMemoryBroker ,
8+ SmartRetryMiddleware ,
9+ TaskiqDepends ,
10+ TaskiqScheduler ,
11+ )
12+ from taskiq .schedule_sources import LabelScheduleSource
13+
14+
15+ @pytest .mark .parametrize (
16+ "retry_count" ,
17+ [0 , random .randint (2 , 5 )],
18+ )
19+ @pytest .mark .anyio
20+ async def test_save_task_id_for_retry (retry_count : int ) -> None :
21+ broker = InMemoryBroker ().with_middlewares (
22+ SmartRetryMiddleware (
23+ default_retry_count = retry_count + 1 ,
24+ default_delay = 0.1 ,
25+ ),
26+ )
27+ scheduler = TaskiqScheduler (broker , [LabelScheduleSource (broker )])
28+
29+ check_interval = 0.5
30+
31+ @broker .task ("exc_task" , retry_on_error = True )
32+ async def exc_task (count : int = 0 , context : "Context" = TaskiqDepends ()) -> int :
33+ retry = int (context .message .labels .get ("_retries" , 0 ))
34+ if retry < count :
35+ raise Exception ("test" )
36+ return retry
37+
38+ await broker .startup ()
39+ await scheduler .startup ()
40+
41+ task_with_retry = await exc_task .kiq (retry_count )
42+ task_with_retry_result = await task_with_retry .wait_result (
43+ check_interval = check_interval ,
44+ )
45+ assert task_with_retry_result .return_value == retry_count
You can’t perform that action at this time.
0 commit comments