Skip to content

Commit

Permalink
Merge pull request #194 from atsign-foundation/xlin-monitor-patch
Browse files Browse the repository at this point in the history
fix: fixed regex missing from heartbeat method
  • Loading branch information
Xlin123 authored May 2, 2024
2 parents c41f88f + 3ab6ebc commit e84c2d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions at_client/atclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,21 +343,21 @@ def __del__(self):
if self.secondary_connection:
self.secondary_connection.disconnect()

def start_monitor(self, regex=""):
def start_monitor(self, regex=".*"):
if self.queue != None:
global should_be_running_lock
what = ""
try:
if self.monitor_connection == None:
what = "construct an AtMonitorConnection"
self.monitor_connection = AtMonitorConnection(queue=self.queue, atsign=self.atsign, address=self.secondary_address, verbose=self.verbose)
self.monitor_connection = AtMonitorConnection(queue=self.queue, atsign=self.atsign, address=self.secondary_address, verbose=self.verbose, regex=regex)
self.monitor_connection.connect()
AuthUtil.authenticate_with_pkam(self.monitor_connection, self.atsign, self.keys)
should_be_running_lock.acquire(blocking=1)
if not self.monitor_connection.running:
should_be_running_lock.release()
what = "call monitor_connection.start_monitor()"
self.monitor_connection.start_monitor(regex)
self.monitor_connection.start_monitor()
else:
should_be_running_lock.release()
except Exception as e:
Expand Down
11 changes: 6 additions & 5 deletions at_client/connections/atmonitorconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class AtMonitorConnection(AtSecondaryConnection):
running: bool = False
should_be_running: bool = False

def __init__(self, queue:queue.Queue, atsign:AtSign, address: Address, context:ssl.SSLContext=ssl.create_default_context(), verbose:bool=True):
def __init__(self, queue:queue.Queue, atsign:AtSign, address: Address, context:ssl.SSLContext=ssl.create_default_context(), verbose:bool=True, regex=".*"):
self.atsign = atsign
self.queue = queue
self.regex = regex
self._verbose = verbose
super().__init__(address, context, verbose)
self._last_heartbeat_sent_time = TimeUtil.current_time_millis()
Expand Down Expand Up @@ -79,7 +80,7 @@ def _start_heart_beat(self):
except Exception as ignore:
pass

def start_monitor(self, regex):
def start_monitor(self):
self._last_heartbeat_sent_time = self._last_heartbeat_ack_time = TimeUtil.current_time_millis()

should_be_running_lock.acquire(blocking=1)
Expand All @@ -100,7 +101,7 @@ def start_monitor(self, regex):
self.running = False
running_lock.release()
return False
self._run(regex)
self._run()
else:
running_lock.release()
return True
Expand All @@ -113,11 +114,11 @@ def stop_monitor(self):
self._last_heartbeat_sent_time = self._last_heartbeat_ack_time = TimeUtil.current_time_millis()
self.disconnect()

def _run(self, regex):
def _run(self):
what = ""
first = True
try:
monitor_cmd = "monitor:" + str(self.last_received_time) + " " + regex
monitor_cmd = "monitor:" + str(self.last_received_time) + " " + self.regex
what = "send monitor command " + monitor_cmd
self.execute_command(command=monitor_cmd, retry_on_exception=True, read_the_response=False)
print("Monitor started on " + str(self.atsign.to_string()))
Expand Down

0 comments on commit e84c2d2

Please sign in to comment.