File tree Expand file tree Collapse file tree 5 files changed +66
-15
lines changed Expand file tree Collapse file tree 5 files changed +66
-15
lines changed Original file line number Diff line number Diff line change @@ -95,17 +95,6 @@ ignore =
95
95
; Found too many public instance attributes
96
96
WPS230,
97
97
98
- ; all init files
99
- __init__.py:
100
- ; ignore not used imports
101
- F401,
102
- ; ignore import with wildcard
103
- F403,
104
- ; Found wrong metadata variable
105
- WPS410,
106
- ; Found commented out cod
107
- E800,
108
-
109
98
per-file-ignores =
110
99
; all tests
111
100
test_*.py,tests.py,tests_*.py,*/tests/*:
@@ -120,6 +109,21 @@ per-file-ignores =
120
109
; Found complex default value
121
110
WPS404,
122
111
112
+ ; all init files
113
+ __init__.py:
114
+ ; ignore not used imports
115
+ F401,
116
+ ; ignore import with wildcard
117
+ F403,
118
+ ; Found wrong metadata variable
119
+ WPS410,
120
+ ; Found commented out cod
121
+ E800,
122
+
123
+ taskiq/serialization.py:
124
+ ; Found commented out code
125
+ E800,
126
+
123
127
exclude =
124
128
./.git,
125
129
./venv,
Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ def __init__(
86
86
"Setting result backend with constructor is deprecated. "
87
87
"Please use `with_result_backend` instead." ,
88
88
TaskiqDeprecationWarning ,
89
+ stacklevel = 2 ,
89
90
)
90
91
if task_id_generator is None :
91
92
task_id_generator = default_id_generator
@@ -94,6 +95,7 @@ def __init__(
94
95
"Setting id generator with constructor is deprecated. "
95
96
"Please use `with_id_generator` instead." ,
96
97
TaskiqDeprecationWarning ,
98
+ stacklevel = 2 ,
97
99
)
98
100
self .middlewares : "List[TaskiqMiddleware]" = []
99
101
self .result_backend = result_backend
Original file line number Diff line number Diff line change @@ -206,14 +206,19 @@ async def run_task( # noqa: C901, WPS210
206
206
)
207
207
dep_ctx = dependency_graph .async_ctx (broker_ctx )
208
208
# Resolve all function's dependencies.
209
- kwargs = await dep_ctx .resolve_kwargs ()
210
-
211
- # We udpate kwargs with kwargs from network.
212
- kwargs .update (message .kwargs )
213
209
214
210
# Start a timer.
215
211
start_time = time ()
212
+
216
213
try :
214
+ # We put kwargs resolving here,
215
+ # to be able to catch any exception (for example ),
216
+ # that happen while resolving dependencies.
217
+ if dep_ctx :
218
+ kwargs = await dep_ctx .resolve_kwargs ()
219
+ # We udpate kwargs with kwargs from network.
220
+ kwargs .update (message .kwargs )
221
+
217
222
# If the function is a coroutine, we await it.
218
223
if asyncio .iscoroutinefunction (target ):
219
224
returned = await target (* message .args , ** kwargs )
Original file line number Diff line number Diff line change
1
+ from typing import Generator
2
+
1
3
import pytest
2
4
5
+ from taskiq .abc .broker import AsyncBroker
6
+
3
7
4
8
@pytest .fixture (scope = "session" )
5
9
def anyio_backend () -> str :
@@ -10,3 +14,17 @@ def anyio_backend() -> str:
10
14
:return: backend name.
11
15
"""
12
16
return "asyncio"
17
+
18
+
19
+ @pytest .fixture (autouse = True )
20
+ def reset_broker () -> Generator [None , None , None ]:
21
+ """
22
+ Restore async broker.
23
+
24
+ This fixtures sets some global
25
+ broker variables to default state.
26
+ """
27
+ yield
28
+ AsyncBroker .available_tasks = {}
29
+ AsyncBroker .is_worker_process = False
30
+ AsyncBroker .is_scheduler_process = False
Original file line number Diff line number Diff line change @@ -20,3 +20,25 @@ async def task(context: Context = TaskiqDepends()) -> None:
20
20
await kicked .wait_result ()
21
21
22
22
assert runs_count == 2
23
+
24
+
25
+ @pytest .mark .anyio
26
+ async def test_requeue_from_dependency () -> None :
27
+ broker = InMemoryBroker ()
28
+
29
+ runs_count = 0
30
+
31
+ async def dep_func (context : Context = TaskiqDepends ()) -> None :
32
+ nonlocal runs_count
33
+ runs_count += 1
34
+ if runs_count < 2 :
35
+ await context .requeue ()
36
+
37
+ @broker .task
38
+ async def task (_ : None = TaskiqDepends (dep_func )) -> None :
39
+ return None
40
+
41
+ kicked = await task .kiq ()
42
+ await kicked .wait_result ()
43
+
44
+ assert runs_count == 2
You can’t perform that action at this time.
0 commit comments