Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/aiida/brokers/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import typing as t
from dataclasses import dataclass

from aiida.common.lang import classproperty

JsonPrimitive = str | int | float | bool | None
JsonValue = JsonPrimitive | list['JsonValue'] | dict[str, 'JsonValue']
BrokerServiceStatus = dict[str, JsonValue]
Expand Down Expand Up @@ -37,8 +39,22 @@ class BrokerConfigField:
class Broker(abc.ABC):
"""Interface for a message broker that facilitates communication with and between process runners."""

ENTRY_POINT_GROUP = 'aiida.brokers'
_config_fields: tuple[BrokerConfigField, ...] = ()

@classproperty
def ENTRY_POINT(cls) -> str: # noqa: N802, N805
"""Return the entry point name of this broker class."""
from aiida.plugins.entry_point import get_entry_point_from_class

group, entry_point = get_entry_point_from_class(cls.__module__, cls.__name__)

if group != cls.ENTRY_POINT_GROUP or entry_point is None:
msg = f'could not determine entry point for `{cls.__name__}` in group `{cls.ENTRY_POINT_GROUP}`'
raise RuntimeError(msg)

return entry_point.name

def __init__(self, profile: Profile) -> None:
"""Construct a new instance.

Expand Down
14 changes: 14 additions & 0 deletions tests/brokers/test_zeromq_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ def test_get_default_config():
assert ZeromqBroker.get_default_config() == {'supervised_by_daemon': True}


def test_entry_point():
"""Test the broker entry point is derived from the class."""
assert ZeromqBroker.ENTRY_POINT == 'core.zeromq'


def test_init_invalid_backend():
"""Test the broker rejects profiles configured for a different backend."""
profile = MagicMock()
profile.process_control_backend = 'core.rabbitmq'

with pytest.raises(ValueError, match=r'should be `core\.zeromq`'):
ZeromqBroker(profile)


class TestZeromqBrokerStatusQueries:
"""Tests for ZeromqBroker status queries (file-based)."""

Expand Down
Loading