@@ -113,6 +113,7 @@ def add(
113113 labels_types = message .labels_types ,
114114 args = message .args ,
115115 kwargs = message .kwargs ,
116+ param_name = None ,
116117 ),
117118 )
118119 return self
@@ -123,4 +124,123 @@ def to_step(self) -> GroupStep:
123124 tasks = list (self .tasks ),
124125 skip_errors = self .skip_errors ,
125126 check_interval = self .check_interval ,
127+ pass_args = False ,
128+ )
129+
130+
131+ class GroupWithArgs (Generic [_S , _T ]):
132+ """
133+ Group of tasks with args.
134+
135+ This class gathers multiple tasks together.
136+ They will run in parallel. The only difference
137+ with Group is that it passes the result
138+ of the previous task as the first argument
139+ to all of the tasks in the group.
140+
141+ :param skip_errors: If True, errors in one task will not affect others.
142+ """
143+
144+ # If skip_errors is set to True,
145+ # We update first generic type to Literal[True].
146+ @overload
147+ def __init__ (
148+ self : "GroupWithArgs[Literal[True], Tuple[()]]" ,
149+ skip_errors : Literal [True ],
150+ check_interval : float = 0.1 ,
151+ ) -> None : ...
152+
153+ @overload
154+ def __init__ (
155+ self : "GroupWithArgs[Literal[False], Tuple[()]]" ,
156+ skip_errors : bool = False ,
157+ check_interval : float = 0.1 ,
158+ ) -> None : ...
159+
160+ def __init__ (
161+ self : "GroupWithArgs[Any, Tuple[()]]" ,
162+ skip_errors : bool = False ,
163+ check_interval : float = 0.1 ,
164+ ) -> None :
165+ self .tasks : Tuple [GroupStepItem , ...] = ()
166+ self .skip_errors = skip_errors
167+ self .check_interval = check_interval
168+
169+ @overload
170+ def add (
171+ self : "GroupWithArgs[Literal[True], Tuple[Unpack[_Tups]]]" ,
172+ task : Union [
173+ AsyncKicker [_Params , Coroutine [Any , Any , _TVal ]],
174+ AsyncKicker [_Params , "CoroutineType[Any, Any, _TVal]" ],
175+ AsyncTaskiqDecoratedTask [_Params , Coroutine [Any , Any , _TVal ]],
176+ AsyncTaskiqDecoratedTask [_Params , "CoroutineType[Any, Any, _TVal]" ],
177+ ],
178+ param_name : Optional [str ] = None ,
179+ ** additional_kwargs : Any ,
180+ ) -> "GroupWithArgs[_S, Tuple[Unpack[_Tups], Optional[_TVal]]]" : ...
181+
182+ @overload
183+ def add (
184+ self : "GroupWithArgs[Literal[False], Tuple[Unpack[_Tups]]]" ,
185+ task : Union [
186+ AsyncKicker [_Params , Coroutine [Any , Any , _TVal ]],
187+ AsyncKicker [_Params , "CoroutineType[Any, Any, _TVal]" ],
188+ AsyncTaskiqDecoratedTask [_Params , Coroutine [Any , Any , _TVal ]],
189+ AsyncTaskiqDecoratedTask [_Params , "CoroutineType[Any, Any, _TVal]" ],
190+ ],
191+ param_name : Optional [str ] = None ,
192+ ** additional_kwargs : Any ,
193+ ) -> "GroupWithArgs[_S, Tuple[Unpack[_Tups], _TVal]]" : ...
194+
195+ @overload
196+ def add (
197+ self : "GroupWithArgs[Literal[True], Tuple[Unpack[_Tups]]]" ,
198+ task : Union [
199+ AsyncKicker [_Params , _TVal ],
200+ AsyncTaskiqDecoratedTask [_Params , _TVal ],
201+ ],
202+ param_name : Optional [str ] = None ,
203+ ** additional_kwargs : Any ,
204+ ) -> "GroupWithArgs[_S, Tuple[Unpack[_Tups], Optional[_TVal]]]" : ...
205+
206+ @overload
207+ def add (
208+ self : "GroupWithArgs[Literal[False], Tuple[Unpack[_Tups]]]" ,
209+ task : Union [
210+ AsyncKicker [_Params , _TVal ],
211+ AsyncTaskiqDecoratedTask [_Params , _TVal ],
212+ ],
213+ param_name : Optional [str ] = None ,
214+ ** additional_kwargs : Any ,
215+ ) -> "GroupWithArgs[_S, Tuple[Unpack[_Tups], _TVal]]" : ...
216+
217+ def add (
218+ self : "GroupWithArgs[Any, Any]" ,
219+ task : Union [AsyncKicker [_Params , Any ], AsyncTaskiqDecoratedTask [_Params , Any ]],
220+ param_name : Optional [str ] = None ,
221+ ** additional_kwargs : Any ,
222+ ) -> "Any" :
223+ """Add task to a group."""
224+ kicker = task .kicker () if isinstance (task , AsyncTaskiqDecoratedTask ) else task
225+ message = kicker ._prepare_message (** additional_kwargs )
226+ self .tasks = (
227+ * self .tasks ,
228+ GroupStepItem (
229+ task_name = message .task_name ,
230+ labels = message .labels ,
231+ labels_types = message .labels_types ,
232+ args = message .args ,
233+ kwargs = message .kwargs ,
234+ param_name = param_name ,
235+ ),
236+ )
237+ return self
238+
239+ def to_step (self ) -> GroupStep :
240+ """Convert group definition to a step."""
241+ return GroupStep (
242+ tasks = list (self .tasks ),
243+ skip_errors = self .skip_errors ,
244+ check_interval = self .check_interval ,
245+ pass_args = True ,
126246 )
0 commit comments