mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
Handle SIGINT and SIGTERM in process_user_activity by closing communication gracefully
(imported from commit dcf813fa8af1aaf5d6cc635268757e40c6c202ab)
This commit is contained in:
@@ -65,3 +65,6 @@ class SimpleQueueClient(object):
|
|||||||
|
|
||||||
def start_consuming(self):
|
def start_consuming(self):
|
||||||
self.channel.start_consuming()
|
self.channel.start_consuming()
|
||||||
|
|
||||||
|
def stop_consuming(self):
|
||||||
|
self.channel.stop_consuming()
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import simplejson
|
|||||||
import pika
|
import pika
|
||||||
from zephyr.lib.actions import process_user_activity_event, process_user_presence_event
|
from zephyr.lib.actions import process_user_activity_event, process_user_presence_event
|
||||||
from zephyr.lib.queue import SimpleQueueClient
|
from zephyr.lib.queue import SimpleQueueClient
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
option_list = BaseCommand.option_list
|
option_list = BaseCommand.option_list
|
||||||
@@ -20,8 +22,15 @@ class Command(BaseCommand):
|
|||||||
print " [x] Received presence %r" % (event,)
|
print " [x] Received presence %r" % (event,)
|
||||||
process_user_presence_event(event)
|
process_user_presence_event(event)
|
||||||
|
|
||||||
|
def signal_handler(signal, frame):
|
||||||
|
print("[*] Closing and disconnecting from queues")
|
||||||
|
activity_queue.stop_consuming()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
print ' [*] Waiting for messages. To exit press CTRL+C'
|
print ' [*] Waiting for messages. To exit press CTRL+C'
|
||||||
activity_queue.register_json_consumer('user_activity', callback_activity)
|
activity_queue.register_json_consumer('user_activity', callback_activity)
|
||||||
activity_queue.register_json_consumer('user_presence', callback_presence)
|
activity_queue.register_json_consumer('user_presence', callback_presence)
|
||||||
activity_queue.start_consuming()
|
activity_queue.start_consuming()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user