Skip to content

Commit

Permalink
Merge pull request #509 from beer-garden/monitor-plugin-dependencies
Browse files Browse the repository at this point in the history
Periodically monitor plugin dependency status
  • Loading branch information
1maple1 authored Oct 4, 2024
2 parents c811ec4 + 7fe1140 commit 77ebeab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Brewtils Changelog
------
TBD

- Plugin will periodically monitor if required dependencies are running to update status accordingly
- Apply MD5 Check Sum of chunked files to ensure files are loaded into memory properly
- Updated Plugin `max_concurrent` to support -1 to utilize the default formula that `concurrent.futures.ThreadPoolExecutor` supports `min(32, os.cpu_count() + 4)`
- Updated SystemClient to utilize the local Garden name for default Namespace if none can be determined
Expand Down
25 changes: 23 additions & 2 deletions brewtils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import appdirs
from box import Box
from datetime import datetime, timezone
from packaging.version import Version
from requests import ConnectionError as RequestsConnectionError

Expand Down Expand Up @@ -268,9 +269,12 @@ def run(self):
self._logger.info("Plugin %s has started", self.unique_name)

try:
check_interval = 60
next_dependency_check = self.get_timestamp(check_interval)
# Need the timeout param so this works correctly in Python 2
while not self._shutdown_event.wait(timeout=0.1):
pass
if self.check_dependencies(next_dependency_check):
next_dependency_check = self.get_timestamp(check_interval)
except KeyboardInterrupt:
self._logger.debug("Received KeyboardInterrupt - shutting down")
except Exception as ex:
Expand Down Expand Up @@ -382,6 +386,13 @@ def _hook(exc_type, exc_value, traceback):

sys.excepthook = _hook

@staticmethod
def get_timestamp(add_time: int = None):
current_timestamp = int(datetime.now(timezone.utc).timestamp())
if add_time:
return current_timestamp + add_time
return current_timestamp

def get_system_dependency(self, require, timeout=300):
wait_time = 0.1
while timeout > 0:
Expand All @@ -407,10 +418,20 @@ def get_system_dependency(self, require, timeout=300):
def await_dependencies(self, requires, config):
for req in requires:
system = self.get_system_dependency(req, config.requires_timeout)
self.logger.info(
self.logger.debug(
f"Resolved system {system} for {req}: {config.name} {config.instance_name}"
)

def check_dependencies(self, next_dependency_check: int):
if self._system.requires and self.get_timestamp() >= next_dependency_check:
try:
self.await_dependencies(self._system.requires, self._config)
if "RUNNING" != self._instance.status:
self._start()
except PluginValidationError:
self._logger.debug(f"Dependency check timeout {self.unique_name}")
return True

def _startup(self):
"""Plugin startup procedure
Expand Down

0 comments on commit 77ebeab

Please sign in to comment.