fix signal handler. black reformats

Signed-off-by: jessicamack <jmack@redhat.com>
This commit is contained in:
jessicamack
2023-04-19 11:12:23 -04:00
parent 919d1e5d40
commit 3fe64ad101
2 changed files with 9 additions and 11 deletions

View File

@@ -35,15 +35,7 @@ class Command(BaseCommand):
def host_metric_summary_monthly_queryset(self, result, offset=0, limit=BATCHED_FETCH_COUNT): def host_metric_summary_monthly_queryset(self, result, offset=0, limit=BATCHED_FETCH_COUNT):
list_of_queryset = list( list_of_queryset = list(
result.values( result.values('id', 'date', 'license_consumed', 'license_capacity', 'hosts_added', 'hosts_deleted', 'indirectly_managed_hosts',).order_by(
'id',
'date',
'license_consumed',
'license_capacity',
'hosts_added',
'hosts_deleted',
'indirectly_managed_hosts',
).order_by(
'date' 'date'
)[offset : offset + limit] )[offset : offset + limit]
) )

View File

@@ -3,6 +3,7 @@ import logging
import os import os
import time import time
import signal import signal
import sys
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
@@ -51,14 +52,19 @@ class Command(BaseCommand):
} }
return json.dumps(payload) return json.dumps(payload)
def notify_listener_and_exit(self, *args):
with pg_bus_conn(new_connection=False) as conn:
conn.notify('web_heartbeet', self.construct_payload(action='offline'))
sys.exit(1)
def do_hearbeat_loop(self): def do_hearbeat_loop(self):
with pg_bus_conn(new_connection=True) as conn: with pg_bus_conn(new_connection=True) as conn:
signal.signal(signal.SIGTERM, self.notify_listener_and_exit)
signal.signal(signal.SIGINT, self.notify_listener_and_exit)
while True: while True:
logger.debug('Sending heartbeat') logger.debug('Sending heartbeat')
conn.notify('web_heartbeet', self.construct_payload()) conn.notify('web_heartbeet', self.construct_payload())
time.sleep(settings.BROADCAST_WEBSOCKET_BEACON_FROM_WEB_RATE_SECONDS) time.sleep(settings.BROADCAST_WEBSOCKET_BEACON_FROM_WEB_RATE_SECONDS)
signal.signal(signal.SIGTERM, conn.notify('web_heartbeet', self.construct_payload(action='offline')))
signal.signal(signal.SIGINT, conn.notify('web_heartbeet', self.construct_payload(action='offline')))
# TODO: Send a message with action=offline if we notice a SIGTERM or SIGINT # TODO: Send a message with action=offline if we notice a SIGTERM or SIGINT
# (wsrelay can use this to remove the node quicker) # (wsrelay can use this to remove the node quicker)