mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 15:09:32 -02:30
Manage the zeromq connection per-pid
This commit is contained in:
@@ -102,6 +102,10 @@ class CallbackModule(object):
|
|||||||
self.logger.propagate = False
|
self.logger.propagate = False
|
||||||
|
|
||||||
def _init_connection(self):
|
def _init_connection(self):
|
||||||
|
self.context = None
|
||||||
|
self.socket = None
|
||||||
|
|
||||||
|
def _start_connection(self):
|
||||||
self.context = zmq.Context()
|
self.context = zmq.Context()
|
||||||
self.socket = self.context.socket(zmq.REQ)
|
self.socket = self.context.socket(zmq.REQ)
|
||||||
self.socket.connect("tcp://127.0.0.1:5556")
|
self.socket.connect("tcp://127.0.0.1:5556")
|
||||||
@@ -119,10 +123,16 @@ class CallbackModule(object):
|
|||||||
})
|
})
|
||||||
for retry_count in xrange(4):
|
for retry_count in xrange(4):
|
||||||
try:
|
try:
|
||||||
|
if not hasattr(self, 'connection_pid'):
|
||||||
|
self.connection_pid = os.getpid()
|
||||||
|
if self.connection_pid != os.getpid():
|
||||||
|
self._init_connection()
|
||||||
|
if self.context is None:
|
||||||
|
self._start_connection()
|
||||||
|
|
||||||
self.socket.send(json.dumps(msg))
|
self.socket.send(json.dumps(msg))
|
||||||
self.logger.debug('Publish: %r, retry=%d', msg, retry_count)
|
self.logger.debug('Publish: %r, retry=%d', msg, retry_count)
|
||||||
reply = self.socket.recv()
|
reply = self.socket.recv()
|
||||||
print("Received reply: " + str(reply))
|
|
||||||
return
|
return
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.info('Publish Exception: %r, retry=%d', e,
|
self.logger.info('Publish Exception: %r, retry=%d', e,
|
||||||
|
|||||||
Reference in New Issue
Block a user