parent
3b5dfcc405
commit
39402cb150
@ -0,0 +1,37 @@
|
||||
import datetime
|
||||
import http.client
|
||||
import json
|
||||
#{
|
||||
# actionList:
|
||||
# [
|
||||
# {
|
||||
# type: <RemoteMachineProcessingRun>,
|
||||
# host: <localhost>,
|
||||
# port: <port>,
|
||||
# bodyObject: <object dict, int, str, list>
|
||||
# }
|
||||
# ]
|
||||
#
|
||||
#}
|
||||
def ProcessingRun(inConfigurationDict):
|
||||
lDateTimeString=datetime.datetime.strftime(datetime.datetime.now(),"%Y.%m.%d %H:%M:%S::%f")
|
||||
lResult={"dateTime":lDateTimeString, "state":"connected", "actionListResult":[]}
|
||||
|
||||
for lItem in inConfigurationDict["actionList"]:
|
||||
#Добавить входные значения
|
||||
lResult["actionListResult"].append({"inArgs":lItem})
|
||||
#Обработка запроса на отправку команды на удаленную машину
|
||||
if lItem["type"]=="RemoteMachineProcessingRun":
|
||||
lHTTPConnection = http.client.HTTPConnection(lItem["host"], lItem["port"], timeout=5)
|
||||
try:
|
||||
lHTTPConnection.request("POST","/ProcessingRun",json.dumps(lItem["bodyObject"]))
|
||||
except Exception as e:
|
||||
#Объединение словарей
|
||||
lResult["actionListResult"][-1] = {**lResult["actionListResult"][-1], **{"state":"disconnected","errorMessage":str(e)}}
|
||||
#lResult["actionListResult"][-1].join({"state":"disconnected","errorMessage":str(e)})
|
||||
else:
|
||||
lHTTPResponse=lHTTPConnection.getresponse()
|
||||
lHTTPResponseByteArray=lHTTPResponse.read()
|
||||
lResult["actionListResult"][-1] = {**lResult["actionListResult"][-1], **json.loads(lHTTPResponseByteArray.decode('utf8'))}
|
||||
#Вернуть результат
|
||||
return lResult
|
Loading…
Reference in new issue