Skip to content

Commit

Permalink
PWMProbes: Start/stop the heartbeat_thread in PWM
Browse files Browse the repository at this point in the history
IBM#38
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
  • Loading branch information
gabe-l-hart committed Jan 23, 2024
1 parent 39956ae commit bc8a6ce
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion oper8/watch_manager/python_watch_manager/python_watch_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ..base import WatchManagerBase
from .filters import get_filters_for_resource_id
from .leader_election import LeadershipManagerBase, get_leader_election_class
from .threads import ReconcileThread, WatchThread
from .threads import HeartbeatThread, ReconcileThread, WatchThread
from .threads.watch import create_resource_watch, get_resource_watches
from .utils import ResourceId, WatchRequest

Expand Down Expand Up @@ -72,6 +72,12 @@ def __init__(
deploy_manager=self.deploy_manager,
leadership_manager=self.leadership_manager,
)
self.heartbeat_thread: Optional[HeartbeatThread] = None
if config.python_watch_manager.heartbeat_file:
self.heartbeat_thread = HeartbeatThread(
config.python_watch_manager.heartbeat_file,
config.python_watch_manager.heartbeat_period,
)

# Start thread for each resource watch
self.controller_watches: List[WatchThread] = []
Expand Down Expand Up @@ -105,6 +111,9 @@ def watch(self) -> bool:
for watch_thread in self.controller_watches:
log.debug("Starting watch_thread: %s", watch_thread)
watch_thread.start_thread()
if self.heartbeat_thread:
log.debug("Starting heartbeat_thread")
self.heartbeat_thread.start()
return True

def wait(self):
Expand Down Expand Up @@ -132,6 +141,8 @@ def stop(self):
watch.stop_thread()
self.reconcile_thread.stop_thread()
self.leadership_manager.release()
if self.heartbeat_thread:
self.heartbeat_thread.stop_thread()

## Helper Functions ###############################################################

Expand Down

0 comments on commit bc8a6ce

Please sign in to comment.