mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-02 02:11:19 +08:00
Access configured messaging backend directly
The accessible configured messaging backend is sigleton. This patch make it possible to access the configured backend and avoid accessing a "private" variable from module messaging. Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import pkg_resources
|
||||
|
||||
from module_build_service.scheduler.parser import FedmsgMessageParser
|
||||
|
||||
from module_build_service import log
|
||||
from module_build_service import conf, log
|
||||
|
||||
|
||||
def publish(topic, msg, conf, service):
|
||||
@@ -109,3 +109,7 @@ for entrypoint in pkg_resources.iter_entry_points("mbs.messaging_backends"):
|
||||
|
||||
if not _messaging_backends:
|
||||
raise ValueError("No messaging plugins are installed or available.")
|
||||
|
||||
# After loading registered messaging backends, the default messaging backend
|
||||
# can be determined by configured messaging backend.
|
||||
default_messaging_backend = _messaging_backends[conf.messaging]
|
||||
|
||||
@@ -31,6 +31,7 @@ import module_build_service.monitor as monitor
|
||||
|
||||
from module_build_service import models, log, conf
|
||||
from module_build_service.db_session import db_session
|
||||
from module_build_service.messaging import default_messaging_backend
|
||||
from module_build_service.scheduler.handlers import greenwave
|
||||
from module_build_service.utils import module_build_state_from_msg
|
||||
from module_build_service.scheduler import events
|
||||
@@ -51,10 +52,9 @@ class MBSConsumer(fedmsg.consumers.FedmsgConsumer):
|
||||
def __init__(self, hub):
|
||||
# Topic setting needs to be done *before* the call to `super`.
|
||||
|
||||
backends = module_build_service.messaging._messaging_backends
|
||||
prefixes = conf.messaging_topic_prefix # This is a list.
|
||||
services = backends[conf.messaging]["services"]
|
||||
suffix = backends[conf.messaging]["topic_suffix"]
|
||||
services = default_messaging_backend["services"]
|
||||
suffix = default_messaging_backend["topic_suffix"]
|
||||
self.topic = [
|
||||
"{}.{}{}".format(prefix.rstrip("."), category, suffix)
|
||||
for prefix, category in itertools.product(prefixes, services)
|
||||
@@ -166,7 +166,7 @@ class MBSConsumer(fedmsg.consumers.FedmsgConsumer):
|
||||
self.shutdown()
|
||||
|
||||
def get_abstracted_msg(self, message):
|
||||
parser = module_build_service.messaging._messaging_backends[conf.messaging].get("parser")
|
||||
parser = default_messaging_backend.get("parser")
|
||||
if parser:
|
||||
try:
|
||||
return parser.parse(message)
|
||||
|
||||
Reference in New Issue
Block a user