2017-11-16 19:54:24 +01:00
|
|
|
# Documented in https://zulip.readthedocs.io/en/latest/subsystems/queuing.html
|
2024-04-16 20:49:37 +02:00
|
|
|
import importlib
|
|
|
|
import pkgutil
|
2023-12-05 15:53:07 +01:00
|
|
|
from typing import List, Optional
|
2017-09-15 09:38:12 +02:00
|
|
|
|
2024-04-16 20:49:37 +02:00
|
|
|
import zerver.worker
|
|
|
|
from zerver.worker.base import QueueProcessingWorker, test_queues, worker_classes
|
2013-08-29 23:41:03 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2023-06-28 02:06:57 +02:00
|
|
|
def get_worker(
|
2023-12-05 15:53:07 +01:00
|
|
|
queue_name: str,
|
|
|
|
*,
|
|
|
|
threaded: bool = False,
|
|
|
|
disable_timeout: bool = False,
|
|
|
|
worker_num: Optional[int] = None,
|
2024-04-16 20:49:37 +02:00
|
|
|
) -> QueueProcessingWorker:
|
|
|
|
if queue_name in {"test", "noop", "noop_batch"}:
|
|
|
|
import_module = "zerver.worker.test"
|
|
|
|
else:
|
|
|
|
import_module = f"zerver.worker.{queue_name}"
|
|
|
|
|
|
|
|
importlib.import_module(import_module)
|
2023-12-05 15:53:07 +01:00
|
|
|
return worker_classes[queue_name](
|
|
|
|
threaded=threaded, disable_timeout=disable_timeout, worker_num=worker_num
|
|
|
|
)
|
2013-08-29 23:41:03 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
|
|
|
def get_active_worker_queues(only_test_queues: bool = False) -> List[str]:
|
2020-10-24 02:24:10 +02:00
|
|
|
"""Returns all (either test, or real) worker queues."""
|
2024-04-16 20:49:37 +02:00
|
|
|
for module_info in pkgutil.iter_modules(zerver.worker.__path__, "zerver.worker."):
|
|
|
|
importlib.import_module(module_info.name)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
return [
|
|
|
|
queue_name
|
2023-01-05 07:26:31 +01:00
|
|
|
for queue_name in worker_classes
|
2021-02-12 08:19:30 +01:00
|
|
|
if bool(queue_name in test_queues) == only_test_queues
|
|
|
|
]
|