Skip to content

Commit

Permalink
Add requires timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
1maple1 committed Aug 19, 2024
1 parent 9e5a394 commit b84f0dd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions brewtils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ def __init__(
groups=None,
prefix_topic=None,
requires=None,
requires_timeout=None,
):
self.name = name
self.description = description
Expand All @@ -780,6 +781,7 @@ def __init__(
self.groups = groups or []
self.prefix_topic = prefix_topic
self.requires = requires or []
self.requires_timeout = requires_timeout

def __str__(self):
return "%s:%s-%s" % (self.namespace, self.name, self.version)
Expand Down
6 changes: 5 additions & 1 deletion brewtils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Plugin(object):
- ``groups``
- ``require``
- ``requires``
- ``requires_timeout``
Connection information tells the Plugin how to communicate with Beer-garden. The
most important of these is the ``bg_host`` (to tell the plugin where to find the
Expand Down Expand Up @@ -176,6 +177,7 @@ class Plugin(object):
require (str): Required system dependency
requires (list): Required systems dependencies
requires_timeout (int): Timeout to wait for dependencies
group (str): Grouping label applied to plugin
groups (list): Grouping labels applied to plugin
Expand Down Expand Up @@ -401,7 +403,7 @@ def get_system_dependency(self, require, timeout=300):

def await_dependencies(self, config):
for req in config.requires:
system = self.get_system_dependency(req)
system = self.get_system_dependency(req, config.requires_timeout)
self.logger.info(
f"Resolved system {system} for {req}: {config.name} {config.instance_name}"
)
Expand Down Expand Up @@ -446,6 +448,7 @@ def _startup(self):
self._admin_processor.startup()

try:
print(self._config)
if self._config.requires:
self.await_dependencies(self._config)
except PluginValidationError:
Expand Down Expand Up @@ -922,6 +925,7 @@ def _setup_system(self, system, plugin_kwargs):
groups=self._config.groups,
prefix_topic=self._config.prefix_topic,
requires=self._config.requires,
requires_timeout=self._config.requires_timeout,
)

return system
Expand Down
1 change: 1 addition & 0 deletions brewtils/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class SystemSchema(BaseSchema):
groups = fields.List(fields.Str(), allow_none=True)
prefix_topic = fields.Str(allow_none=True)
requires = fields.List(fields.Str(), allow_none=True)
requires_timeout = fields.Integer(allow_none=True)


class SystemDomainIdentifierSchema(BaseSchema):
Expand Down
5 changes: 5 additions & 0 deletions brewtils/specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ def _is_json_dict(s):
"required": False,
"default": [],
},
"requires_timeout": {
"type": "int",
"description": "The dependency timeout to use",
"default": 300,
},
}

_PLUGIN_SPEC = {
Expand Down
2 changes: 2 additions & 0 deletions test/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def test_kwargs(self, client, bg_system):
prefix_topic="custom.topic",
require="SystemA",
requires=["SystemB"],
requires_timeout=200,
)

assert plugin._logger == logger
Expand All @@ -186,6 +187,7 @@ def test_kwargs(self, client, bg_system):
assert "SystemA" == plugin._config.require
assert "SystemB" in plugin._config.requires
assert "SystemA" not in plugin._config.requires
assert plugin._config.requires_timeout == 200

def test_env(self, client, bg_system):
os.environ["BG_HOST"] = "remotehost"
Expand Down

0 comments on commit b84f0dd

Please sign in to comment.