Skip to content

Commit 85d9a09

Browse files
committed
fix bug with heartbeat
the time in sleep was larger than timeout for rabbitmq, resulting in rabbitmq closing channel
1 parent d91cfc3 commit 85d9a09

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pyclowder/connectors.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import os
3838
import pickle
3939
import subprocess
40+
import sys
4041
import time
4142
import tempfile
4243
import threading
@@ -808,10 +809,13 @@ def send_heartbeat(self):
808809
'queue': self.rabbitmq_queue,
809810
'extractor_info': self.extractor_info
810811
}
812+
next_heartbeat = time.time()
811813
while self.thread:
812814
try:
813-
self.channel.basic_publish(exchange='extractors', routing_key='', body=json.dumps(message))
814-
time.sleep(self.heartbeat)
815+
self.channel.connection.process_data_events()
816+
if time.time() >= next_heartbeat:
817+
self.channel.basic_publish(exchange='extractors', routing_key='', body=json.dumps(message))
818+
next_heartbeat = time.time() + self.heartbeat
815819
except SystemExit:
816820
raise
817821
except KeyboardInterrupt:
@@ -820,6 +824,8 @@ def send_heartbeat(self):
820824
raise
821825
except Exception: # pylint: disable=broad-except
822826
logging.getLogger(__name__).exception("Error while sending heartbeat.")
827+
sys.exit(-1)
828+
time.sleep(1)
823829

824830

825831
class RabbitMQHandler(Connector):

0 commit comments

Comments
 (0)