Skip to content

BaseBroker - пишем свой Брокер

Base Broker.

BaseBroker

Bases: Generic[TAsyncFlag], ABC

BaseBroker - An abstract class that is the foundation for Brokers.

Example

from qtasks import QueueTasks
from qtasks.brokers.base import BaseBroker

class MyBroker(BaseBroker):
    def __init__(self, name: str = None, storage: BaseStorage = None):
        super().__init__(name=name, storage=storage)
        pass
Source code in src/qtasks/brokers/base.py
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
class BaseBroker(Generic[TAsyncFlag], ABC):
    """
    `BaseBroker` - An abstract class that is the foundation for Brokers.

    ## Example

    ```python
    from qtasks import QueueTasks
    from qtasks.brokers.base import BaseBroker

    class MyBroker(BaseBroker):
        def __init__(self, name: str = None, storage: BaseStorage = None):
            super().__init__(name=name, storage=storage)
            pass
    ```
    """

    def __init__(
        self,
        storage: Annotated[
            BaseStorage[TAsyncFlag],
            Doc("""
                    Storage `qtasks.storages.base.BaseStorage`.

                    Default: `None`.
                    """),
        ],
        name: Annotated[
            str | None,
            Doc("""
                    Project name. This name can be used for tags for Brokers.

                    Default: `None`.
                    """),
        ] = None,
        log: Annotated[
            Logger | None,
            Doc("""
                    Logger.

                    Default: `qtasks.logs.Logger`.
                    """),
        ] = None,
        config: Annotated[
            QueueConfig | None,
            Doc("""
                    Config.

                    Default: `qtasks.configs.config.QueueConfig`.
                    """),
        ] = None,
        events: Annotated[
            Optional[BaseEvents],
            Doc("""
                    Events.

                    Default: `None`.
                    """),
        ] = None,
    ):
        """
        BaseBroker initialization.

        Args:
            name (str, optional): Project name. Default: `None`.
            storage (BaseStorage, optional): Storage. Default: `None`.
            log (Logger, optional): Logger. Default: `None`.
            config (QueueConfig, optional): Config. Default: `None`.
            events (BaseEvents, optional): Events. Default: `None`.
        """
        self.name = name
        self.config = config or QueueConfig()
        self.log = (
            log.with_subname("Broker")
            if log
            else Logger(
                name=self.name or "QueueTasks",
                subname="Broker",
                default_level=self.config.logs_default_level_server,
                format=self.config.logs_format,
            )
        )
        self.events = events

        self.storage = storage

        self.plugins: dict[str, list[BasePlugin]] = {}

        self.init_plugins()

    @overload
    def add(
        self: BaseBroker[Literal[False]],
        task_name: Annotated[
            str,
            Doc("""
                    Task name.
                    """),
        ],
        priority: Annotated[
            int,
            Doc("""
                    Task priority.

                    Default: `0`.
                    """),
        ] = 0,
        extra: Annotated[
            dict | None,
            Doc("""
                    Additional task parameters.
                    """),
        ] = None,
        args: Annotated[
            tuple | None,
            Doc("""
                    Task arguments of type args.
                    """),
        ] = None,
        kwargs: Annotated[
            dict | None,
            Doc("""
                    Task arguments of type kwargs.
                    """),
        ] = None,
    ) -> Task: ...

    @overload
    async def add(
        self: BaseBroker[Literal[True]],
        task_name: Annotated[
            str,
            Doc("""
                    Task name.
                    """),
        ],
        priority: Annotated[
            int,
            Doc("""
                    Task priority.

                    Default: `0`.
                    """),
        ] = 0,
        extra: Annotated[
            dict | None,
            Doc("""
                    Additional task parameters.
                    """),
        ] = None,
        args: Annotated[
            tuple | None,
            Doc("""
                    Task arguments of type args.
                    """),
        ] = None,
        kwargs: Annotated[
            dict | None,
            Doc("""
                    Task arguments of type kwargs.
                    """),
        ] = None,
    ) -> Task: ...

    @abstractmethod
    def add(
        self,
        task_name: Annotated[
            str,
            Doc("""
                    Task name.
                    """),
        ],
        priority: Annotated[
            int,
            Doc("""
                    Task priority.

                    Default: `0`.
                    """),
        ] = 0,
        extra: Annotated[
            dict | None,
            Doc("""
                    Additional task parameters.
                    """),
        ] = None,
        args: Annotated[
            tuple | None,
            Doc("""
                    Task arguments of type args.
                    """),
        ] = None,
        kwargs: Annotated[
            dict | None,
            Doc("""
                    Task arguments of type kwargs.
                    """),
        ] = None,
    ) -> Task | Awaitable[Task]:
        """
        Adding a task to the broker.

        Args:
            task_name (str): The name of the task.
            priority (int, optional): Task priority. Default: `0`.
            extra (dict, optional): Additional task parameters. Default: `None`.
            args (tuple, optional): Task arguments of type args. Default: `None`.
            kwargs (dict, optional): Task arguments of type kwargs. Default: `None`.

        Returns:
            Task: `schemas.task.Task`
        """
        pass

    @overload
    def get(
        self: BaseBroker[Literal[False]],
        uuid: Annotated[
            UUID | str,
            Doc("""
                    UUID of the task.
                    """),
        ],
    ) -> Task | None: ...

    @overload
    async def get(
        self: BaseBroker[Literal[True]],
        uuid: Annotated[
            UUID | str,
            Doc("""
                    UUID of the task.
                    """),
        ],
    ) -> Task | None: ...

    @abstractmethod
    def get(
        self,
        uuid: Annotated[
            UUID | str,
            Doc("""
                    UUID of the task.
                    """),
        ],
    ) -> Task | None | Awaitable[Task | None]:
        """
        Obtaining information about a task.

        Args:
            uuid (UUID|str): UUID of the task.

        Returns:
            Task|None: If there is task information, returns `schemas.task.Task`, otherwise `None`.
        """
        pass

    @overload
    def update(
        self: BaseBroker[Literal[False]],
        **kwargs: Annotated[
            Any,
            Doc("""
                    Update arguments for storage type kwargs.
                    """),
        ],
    ) -> None: ...

    @overload
    async def update(
        self: BaseBroker[Literal[True]],
        **kwargs: Annotated[
            Any,
            Doc("""
                    Update arguments for storage type kwargs.
                    """),
        ],
    ) -> None: ...

    @abstractmethod
    def update(
        self,
        **kwargs: Annotated[
            Any,
            Doc("""
                    Update arguments for storage type kwargs.
                    """),
        ],
    ) -> None | Awaitable[None]:
        """
        Updates task information.

        Args:
            kwargs (dict, optional): task data of type kwargs.
        """
        pass

    @overload
    def start(
        self: BaseBroker[Literal[False]],
        worker: Annotated[
            Optional[BaseWorker],
            Doc("""
                    Worker class.

                    Default: `None`.
                    """),
        ] = None,
    ) -> None: ...

    @overload
    async def start(
        self: BaseBroker[Literal[True]],
        worker: Annotated[
            Optional[BaseWorker],
            Doc("""
                    Worker class.

                    Default: `None`.
                    """),
        ] = None,
    ) -> None: ...

    @abstractmethod
    def start(
        self,
        worker: Annotated[
            Optional[BaseWorker],
            Doc("""
                    Worker class.

                    Default: `None`.
                    """),
        ] = None,
    ) -> None | Awaitable[None]:
        """
        Launching the Broker. This function is enabled by the main `QueueTasks` instance via `run_forever`.

        Args:
            worker (BaseWorker, optional): Worker class. Default: `None`.
        """
        pass

    @overload
    def stop(
        self: BaseBroker[Literal[False]],
    ) -> None: ...

    @overload
    async def stop(
        self: BaseBroker[Literal[True]],
    ) -> None: ...

    @abstractmethod
    def stop(self) -> None | Awaitable[None]:
        """The broker stops. This function is invoked by the main `QueueTasks` instance after the `run_forever` function completes."""
        pass

    def update_config(
        self,
        config: Annotated[
            QueueConfig,
            Doc("""
                    Config.
                    """),
        ],
    ) -> None:
        """
        Updates the broker config.

        Args:
            config (QueueConfig): Config.
        """
        self.config = config
        return

    def add_plugin(
        self,
        plugin: Annotated[
            BasePlugin,
            Doc("""
                    Plugin.
                    """),
        ],
        trigger_names: Annotated[
            list[str] | None,
            Doc("""
                    The name of the triggers for the plugin.

                    Default: Default: will be added to `Globals`.
                    """),
        ] = None,
    ) -> None:
        """
        Add a plugin to the class.

        Args:
            plugin (BasePlugin): Plugin
            trigger_names (List[str], optional): The name of the triggers for the plugin. Default: will be added to `Globals`.
        """
        trigger_names = trigger_names or ["Globals"]

        for name in trigger_names:
            if name not in self.plugins:
                self.plugins.update({name: [plugin]})
            else:
                self.plugins[name].append(plugin)
        return

    @overload
    def flush_all(self: BaseBroker[Literal[False]]) -> None: ...

    @overload
    async def flush_all(self: BaseBroker[Literal[True]]) -> None: ...

    def flush_all(self) -> None | Awaitable[None]:
        """Delete all data."""
        pass

    def init_plugins(self):
        """Initializing plugins."""
        pass

    @overload
    def remove_finished_task(
        self: BaseBroker[Literal[False]],
        task_broker: Annotated[
            TaskPrioritySchema,
            Doc("""
                    Priority task diagram.
                    """),
        ],
        model: Annotated[
            TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema,
            Doc("""
                    Model of the task result.
                    """),
        ],
    ) -> None: ...

    @overload
    async def remove_finished_task(
        self: BaseBroker[Literal[True]],
        task_broker: Annotated[
            TaskPrioritySchema,
            Doc("""
                    Priority task diagram.
                    """),
        ],
        model: Annotated[
            TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema,
            Doc("""
                    Model of the task result.
                    """),
        ],
    ) -> None: ...

    def remove_finished_task(
        self,
        task_broker: Annotated[
            TaskPrioritySchema,
            Doc("""
                    Priority task diagram.
                    """),
        ],
        model: Annotated[
            TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema,
            Doc("""
                    Model of the task result.
                    """),
        ],
    ) -> None | Awaitable[None]:
        """
        Updates storage data via the `self.storage.remove_finished_task` function.

        Args:
            task_broker (TaskPrioritySchema): The priority task schema.
            model (TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema): Model of the task result.
        """
        pass

    def _dynamic_model(
        self,
        model: Annotated[
            TaskStatusNewSchema,
            Doc("""
                    Task model.
                    """),
        ],
        extra: Annotated[
            dict,
            Doc("""
                    Additional fields.
                    """),
        ],
    ):
        # Get the names of standard fields
        task_field_names = {f.name for f in fields(TaskStatusNewSchema)}

        # We are looking for additional keys
        extra_fields = []
        extra_values = {}

        for key, value in extra.items():
            if key not in task_field_names:
                # Typing is primitive - can be improved
                field_type = type(value)
                extra_fields.append((key, field_type, field(default=None)))
                extra_values[key] = value

        # Create a new dataclass with additional fields
        if extra_fields:
            NewTask = make_dataclass(
                "TaskStatusNewSchema", extra_fields, bases=(TaskStatusNewSchema,)
            )
        else:
            NewTask = TaskStatusNewSchema

        # Let's combine all the arguments
        return NewTask(**asdict(model), **extra_values)

__init__(storage, name=None, log=None, config=None, events=None)

BaseBroker initialization.

Parameters:

Name Type Description Default
name str

Project name. Default: None.

None
storage BaseStorage

Storage. Default: None.

required
log Logger

Logger. Default: None.

None
config QueueConfig

Config. Default: None.

None
events BaseEvents

Events. Default: None.

None
Source code in src/qtasks/brokers/base.py
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def __init__(
    self,
    storage: Annotated[
        BaseStorage[TAsyncFlag],
        Doc("""
                Storage `qtasks.storages.base.BaseStorage`.

                Default: `None`.
                """),
    ],
    name: Annotated[
        str | None,
        Doc("""
                Project name. This name can be used for tags for Brokers.

                Default: `None`.
                """),
    ] = None,
    log: Annotated[
        Logger | None,
        Doc("""
                Logger.

                Default: `qtasks.logs.Logger`.
                """),
    ] = None,
    config: Annotated[
        QueueConfig | None,
        Doc("""
                Config.

                Default: `qtasks.configs.config.QueueConfig`.
                """),
    ] = None,
    events: Annotated[
        Optional[BaseEvents],
        Doc("""
                Events.

                Default: `None`.
                """),
    ] = None,
):
    """
    BaseBroker initialization.

    Args:
        name (str, optional): Project name. Default: `None`.
        storage (BaseStorage, optional): Storage. Default: `None`.
        log (Logger, optional): Logger. Default: `None`.
        config (QueueConfig, optional): Config. Default: `None`.
        events (BaseEvents, optional): Events. Default: `None`.
    """
    self.name = name
    self.config = config or QueueConfig()
    self.log = (
        log.with_subname("Broker")
        if log
        else Logger(
            name=self.name or "QueueTasks",
            subname="Broker",
            default_level=self.config.logs_default_level_server,
            format=self.config.logs_format,
        )
    )
    self.events = events

    self.storage = storage

    self.plugins: dict[str, list[BasePlugin]] = {}

    self.init_plugins()

add(task_name, priority=0, extra=None, args=None, kwargs=None) abstractmethod

add(task_name: Annotated[str, Doc('\n                    Task name.\n                    ')], priority: Annotated[int, Doc('\n                    Task priority.\n\n                    Default: `0`.\n                    ')] = 0, extra: Annotated[dict | None, Doc('\n                    Additional task parameters.\n                    ')] = None, args: Annotated[tuple | None, Doc('\n                    Task arguments of type args.\n                    ')] = None, kwargs: Annotated[dict | None, Doc('\n                    Task arguments of type kwargs.\n                    ')] = None) -> Task
add(task_name: Annotated[str, Doc('\n                    Task name.\n                    ')], priority: Annotated[int, Doc('\n                    Task priority.\n\n                    Default: `0`.\n                    ')] = 0, extra: Annotated[dict | None, Doc('\n                    Additional task parameters.\n                    ')] = None, args: Annotated[tuple | None, Doc('\n                    Task arguments of type args.\n                    ')] = None, kwargs: Annotated[dict | None, Doc('\n                    Task arguments of type kwargs.\n                    ')] = None) -> Task

Adding a task to the broker.

Parameters:

Name Type Description Default
task_name str

The name of the task.

required
priority int

Task priority. Default: 0.

0
extra dict

Additional task parameters. Default: None.

None
args tuple

Task arguments of type args. Default: None.

None
kwargs dict

Task arguments of type kwargs. Default: None.

None

Returns:

Name Type Description
Task Task | Awaitable[Task]

schemas.task.Task

Source code in src/qtasks/brokers/base.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
@abstractmethod
def add(
    self,
    task_name: Annotated[
        str,
        Doc("""
                Task name.
                """),
    ],
    priority: Annotated[
        int,
        Doc("""
                Task priority.

                Default: `0`.
                """),
    ] = 0,
    extra: Annotated[
        dict | None,
        Doc("""
                Additional task parameters.
                """),
    ] = None,
    args: Annotated[
        tuple | None,
        Doc("""
                Task arguments of type args.
                """),
    ] = None,
    kwargs: Annotated[
        dict | None,
        Doc("""
                Task arguments of type kwargs.
                """),
    ] = None,
) -> Task | Awaitable[Task]:
    """
    Adding a task to the broker.

    Args:
        task_name (str): The name of the task.
        priority (int, optional): Task priority. Default: `0`.
        extra (dict, optional): Additional task parameters. Default: `None`.
        args (tuple, optional): Task arguments of type args. Default: `None`.
        kwargs (dict, optional): Task arguments of type kwargs. Default: `None`.

    Returns:
        Task: `schemas.task.Task`
    """
    pass

add_plugin(plugin, trigger_names=None)

Add a plugin to the class.

Parameters:

Name Type Description Default
plugin BasePlugin

Plugin

required
trigger_names List[str]

The name of the triggers for the plugin. Default: will be added to Globals.

None
Source code in src/qtasks/brokers/base.py
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
def add_plugin(
    self,
    plugin: Annotated[
        BasePlugin,
        Doc("""
                Plugin.
                """),
    ],
    trigger_names: Annotated[
        list[str] | None,
        Doc("""
                The name of the triggers for the plugin.

                Default: Default: will be added to `Globals`.
                """),
    ] = None,
) -> None:
    """
    Add a plugin to the class.

    Args:
        plugin (BasePlugin): Plugin
        trigger_names (List[str], optional): The name of the triggers for the plugin. Default: will be added to `Globals`.
    """
    trigger_names = trigger_names or ["Globals"]

    for name in trigger_names:
        if name not in self.plugins:
            self.plugins.update({name: [plugin]})
        else:
            self.plugins[name].append(plugin)
    return

flush_all()

flush_all() -> None
flush_all() -> None

Delete all data.

Source code in src/qtasks/brokers/base.py
456
457
458
def flush_all(self) -> None | Awaitable[None]:
    """Delete all data."""
    pass

get(uuid) abstractmethod

get(uuid: Annotated[UUID | str, Doc('\n                    UUID of the task.\n                    ')]) -> Task | None
get(uuid: Annotated[UUID | str, Doc('\n                    UUID of the task.\n                    ')]) -> Task | None

Obtaining information about a task.

Parameters:

Name Type Description Default
uuid UUID | str

UUID of the task.

required

Returns:

Type Description
Task | None | Awaitable[Task | None]

Task|None: If there is task information, returns schemas.task.Task, otherwise None.

Source code in src/qtasks/brokers/base.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
@abstractmethod
def get(
    self,
    uuid: Annotated[
        UUID | str,
        Doc("""
                UUID of the task.
                """),
    ],
) -> Task | None | Awaitable[Task | None]:
    """
    Obtaining information about a task.

    Args:
        uuid (UUID|str): UUID of the task.

    Returns:
        Task|None: If there is task information, returns `schemas.task.Task`, otherwise `None`.
    """
    pass

init_plugins()

Initializing plugins.

Source code in src/qtasks/brokers/base.py
460
461
462
def init_plugins(self):
    """Initializing plugins."""
    pass

remove_finished_task(task_broker, model)

remove_finished_task(task_broker: Annotated[TaskPrioritySchema, Doc('\n                    Priority task diagram.\n                    ')], model: Annotated[TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema, Doc('\n                    Model of the task result.\n                    ')]) -> None
remove_finished_task(task_broker: Annotated[TaskPrioritySchema, Doc('\n                    Priority task diagram.\n                    ')], model: Annotated[TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema, Doc('\n                    Model of the task result.\n                    ')]) -> None

Updates storage data via the self.storage.remove_finished_task function.

Parameters:

Name Type Description Default
task_broker TaskPrioritySchema

The priority task schema.

required
model TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema

Model of the task result.

required
Source code in src/qtasks/brokers/base.py
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
def remove_finished_task(
    self,
    task_broker: Annotated[
        TaskPrioritySchema,
        Doc("""
                Priority task diagram.
                """),
    ],
    model: Annotated[
        TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema,
        Doc("""
                Model of the task result.
                """),
    ],
) -> None | Awaitable[None]:
    """
    Updates storage data via the `self.storage.remove_finished_task` function.

    Args:
        task_broker (TaskPrioritySchema): The priority task schema.
        model (TaskStatusSuccessSchema | TaskStatusProcessSchema | TaskStatusErrorSchema | TaskStatusCancelSchema): Model of the task result.
    """
    pass

start(worker=None) abstractmethod

start(worker: Annotated[Optional[BaseWorker], Doc('\n                    Worker class.\n\n                    Default: `None`.\n                    ')] = None) -> None
start(worker: Annotated[Optional[BaseWorker], Doc('\n                    Worker class.\n\n                    Default: `None`.\n                    ')] = None) -> None

Launching the Broker. This function is enabled by the main QueueTasks instance via run_forever.

Parameters:

Name Type Description Default
worker BaseWorker

Worker class. Default: None.

None
Source code in src/qtasks/brokers/base.py
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
@abstractmethod
def start(
    self,
    worker: Annotated[
        Optional[BaseWorker],
        Doc("""
                Worker class.

                Default: `None`.
                """),
    ] = None,
) -> None | Awaitable[None]:
    """
    Launching the Broker. This function is enabled by the main `QueueTasks` instance via `run_forever`.

    Args:
        worker (BaseWorker, optional): Worker class. Default: `None`.
    """
    pass

stop() abstractmethod

stop() -> None
stop() -> None

The broker stops. This function is invoked by the main QueueTasks instance after the run_forever function completes.

Source code in src/qtasks/brokers/base.py
394
395
396
397
@abstractmethod
def stop(self) -> None | Awaitable[None]:
    """The broker stops. This function is invoked by the main `QueueTasks` instance after the `run_forever` function completes."""
    pass

update(**kwargs) abstractmethod

update(**kwargs: Annotated[Any, Doc('\n                    Update arguments for storage type kwargs.\n                    ')]) -> None
update(**kwargs: Annotated[Any, Doc('\n                    Update arguments for storage type kwargs.\n                    ')]) -> None

Updates task information.

Parameters:

Name Type Description Default
kwargs dict

task data of type kwargs.

{}
Source code in src/qtasks/brokers/base.py
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@abstractmethod
def update(
    self,
    **kwargs: Annotated[
        Any,
        Doc("""
                Update arguments for storage type kwargs.
                """),
    ],
) -> None | Awaitable[None]:
    """
    Updates task information.

    Args:
        kwargs (dict, optional): task data of type kwargs.
    """
    pass

update_config(config)

Updates the broker config.

Parameters:

Name Type Description Default
config QueueConfig

Config.

required
Source code in src/qtasks/brokers/base.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
def update_config(
    self,
    config: Annotated[
        QueueConfig,
        Doc("""
                Config.
                """),
    ],
) -> None:
    """
    Updates the broker config.

    Args:
        config (QueueConfig): Config.
    """
    self.config = config
    return