Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from kube-HPC/producer_process
Producer process
- Loading branch information
Showing
7 changed files
with
136 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
hkube_python_wrapper/communication/streaming/producerProcess.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from hkube_python_wrapper.communication.streaming.MessageProducer import MessageProducer | ||
from hkube_python_wrapper.util.logger import log | ||
from hkube_python_wrapper.wrapper.messages import messages | ||
|
||
|
||
|
||
class ProducerRunner: | ||
def __init__(self, method_invoke_queue, statistics_queue, options, childs, producerConfig, node): | ||
self._options = options | ||
self.node = node | ||
self._method_invoke_queue = method_invoke_queue | ||
self._statistics_queue = statistics_queue | ||
self._wsc = None | ||
self.messageProducer = None | ||
self._childs = childs | ||
self._producerConfig = producerConfig | ||
|
||
def run(self): | ||
self._setupStreamingProducer() | ||
while True: | ||
arg = self._method_invoke_queue.get() # Get data from the queue | ||
if arg.get("action") == 'stop': | ||
print ("got stop") | ||
self.messageProducer.close(arg.get("force")) | ||
print("stopeped") | ||
self._method_invoke_queue.put("done") | ||
print("sent back") | ||
break # Exit loop if 'exit' is received | ||
if (arg.get("action")=="queuesize"): | ||
self._method_invoke_queue.put(len(self.messageProducer.adapter.messageQueue.queue)) | ||
self.messageProducer.produce(arg.get("flow"), arg.get("msg")) | ||
|
||
def _setupStreamingProducer(self): | ||
def onStatistics(statistics): | ||
self._sendStatistics(statistics) | ||
|
||
self.messageProducer = MessageProducer(self._producerConfig, self._childs, self.node) | ||
self.messageProducer.registerStatisticsListener(onStatistics) | ||
if (self._childs): | ||
self.messageProducer.start() | ||
|
||
|
||
def _sendStatistics(self, data): | ||
try: | ||
self._statistics_queue.put(data) | ||
except Exception as e: | ||
self.sendError(e) | ||
|
||
def sendError(self, error): | ||
try: | ||
log.error(error) | ||
self._wsc.send({ | ||
'command': messages.outgoing.error, | ||
'error': { | ||
'code': 'Failed', | ||
'message': str(error) | ||
} | ||
}) | ||
except Exception as e: | ||
log.error(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
|
||
here = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
VERSION = '2.6.0-dev10' | ||
|
||
VERSION = '2.6.0-dev13' | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters