catch SIGTERM or SIGINT and send offline message

Signed-off-by: jessicamack <jmack@redhat.com>
This commit is contained in:
jessicamack
2023-04-13 15:21:59 -04:00
parent 7fda4b0675
commit 919d1e5d40

View File

@@ -2,6 +2,7 @@ import json
import logging import logging
import os import os
import time import time
import signal
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
@@ -56,6 +57,8 @@ class Command(BaseCommand):
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)