Skip to content

Commit

Permalink
Add command to clear queue
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjohndyer committed Aug 5, 2024
1 parent 7bd0a9b commit dd9b3f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions gtecs/alert/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ def get_queue(self):
# We could return raw payloads I guess...
return [notice.ivorn for notice in self.notice_queue]

def clear_queue(self):
"""Clear the current notice queue."""
self.notice_queue = []


def run():
"""Start the sentinel."""
Expand Down
19 changes: 14 additions & 5 deletions scripts/sentinel
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,19 @@ def query(command, args):
print(proxy.ingest_from_file(args[0]))

elif command == 'queue':
with Pyro4.Proxy(params.PYRO_URI) as proxy:
queue = proxy.get_queue()
print(f'There are {len(queue)} notices currently in the queue')
for i, ivorn in enumerate(queue):
print(i, ivorn)
if len(args) == 0:
with Pyro4.Proxy(params.PYRO_URI) as proxy:
queue = proxy.get_queue()
print(f'There are {len(queue)} notices currently in the queue')
for i, ivorn in enumerate(queue):
print(i, ivorn)
elif len(args) == 1 and args[0] == 'clear':
with Pyro4.Proxy(params.PYRO_URI) as proxy:
proxy.clear_queue()
print('Queue cleared')
else:
print('ERROR: Invalid arguments for "queue" command')
print('Usage: sentinel queue [clear]')

elif command == 'topics':
with Pyro4.Proxy(params.PYRO_URI) as proxy:
Expand All @@ -97,6 +105,7 @@ def print_instructions():
' shutdown shut down the sentinel',
' ingest [path|ivorn] add the given notice to the queue',
' queue print the notices currently in the queue',
' queue clear clear all notices currently in the queue',
' topics print all subscribed Kafka topics',
' log [tail args] print sentinel log (alias for tail)',
' help print these instructions',
Expand Down

0 comments on commit dd9b3f7

Please sign in to comment.