Fix Request/Answer queries

This commit is contained in:
Ivan Vazhenin
2023-04-02 12:39:42 +03:00
parent 4283e2c161
commit cd0725acf3
2 changed files with 44 additions and 22 deletions

41
main.py
View File

@@ -1,3 +1,6 @@
import asyncio
import threading
from queue import Queue
import datetime import datetime
import json import json
from uuid import uuid4, UUID from uuid import uuid4, UUID
@@ -15,6 +18,14 @@ import zipfile
PASSWORD = 'gost_2012$a742ec53198ec2a5027086fba8814a89982a57112d1a72d02260161108f39b50' PASSWORD = 'gost_2012$a742ec53198ec2a5027086fba8814a89982a57112d1a72d02260161108f39b50'
tasks = Queue()
def run_tasks():
while True:
task = tasks.get()
task()
# Expose a function # Expose a function
def list_contents(dir_name): def list_contents(dir_name):
@@ -45,6 +56,7 @@ def restore_uuid(oid):
def load_catalog(params, files, url): def load_catalog(params, files, url):
print('load_catalog')
date = datetime.datetime.now() date = datetime.datetime.now()
rxmls = RequestXmlService() rxmls = RequestXmlService()
req = ET.fromstring(params['query_data']) req = ET.fromstring(params['query_data'])
@@ -62,6 +74,7 @@ def load_catalog(params, files, url):
'query_data': ET.tostring(res, encoding='unicode', xml_declaration=True) 'query_data': ET.tostring(res, encoding='unicode', xml_declaration=True)
} }
catalog = get_catalog() catalog = get_catalog()
print('Catalog_loaded')
filename = uuid4().hex filename = uuid4().hex
filepath = '/tmp/' + filename filepath = '/tmp/' + filename
zipf = zipfile.ZipFile(filepath, "w") zipf = zipfile.ZipFile(filepath, "w")
@@ -161,15 +174,19 @@ def get_metadata(params, files, url):
proxy.send(response_params, response_files, 'http://10.10.8.27:9000/') proxy.send(response_params, response_files, 'http://10.10.8.27:9000/')
def run_task(query_type, params, files, url):
if query_type == 4:
tasks.put(lambda: load_catalog(params, files, url))
if query_type == 1:
tasks.put(lambda: get_objects(params, files, url))
if query_type == 24:
tasks.put(lambda: get_metadata(params, files, url))
def accept(params, files, url): def accept(params, files, url):
print(params, files, url) print(params, files, url)
print('Accept') print('Accept')
if params['query_type'] == 4: run_task(params['query_type'], params, files, url)
load_catalog(params, files, url)
if params['query_type'] == 1:
get_objects(params, files, url)
if params['query_type'] == 24:
get_metadata(params, files, url)
return True return True
@@ -188,6 +205,9 @@ def main():
server.register_function(accept) server.register_function(accept)
server.register_function(onSent) server.register_function(onSent)
thread = threading.Thread(target=run_tasks)
thread.start()
try: try:
server.serve_forever() server.serve_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
@@ -195,11 +215,12 @@ def main():
def test(): def test():
params = {"from": "tcp://kptsp_vb", "query_data": "<?xml version=\"1.0\" encoding=\"utf-8\"?><request><header parcel_id=\"990715ba919544a98f22cc7d3b0d9e8d\"/><getMetadataByIds><chart id=\"fc44343bd1654ee7b03ac1731567bbfd\"/></getMetadataByIds></request>", "query_type": 24, "to": "tcp://bnd127", "user_id": "3302", "ts_added": 1679825320.653038} #params = {"from": "tcp://kptsp_vb", "query_data": "<?xml version=\"1.0\" encoding=\"utf-8\"?><request><header parcel_id=\"990715ba919544a98f22cc7d3b0d9e8d\"/><getMetadataByIds><chart id=\"fc44343bd1654ee7b03ac1731567bbfd\"/></getMetadataByIds></request>", "query_type": 24, "to": "tcp://bnd127", "user_id": "3302", "ts_added": 1679825320.653038}
files = [] #files = []
url = 'http://127.0.0.1:7000/xmlrpc' #url = 'http://127.0.0.1:7000/xmlrpc'
# accept(params, files, url) # accept(params, files, url)
get_metadata(params, files, url) #get_metadata(params, files, url)
get_catalog()
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -2,43 +2,44 @@ from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport from gql.transport.aiohttp import AIOHTTPTransport
transport = AIOHTTPTransport(url="https://gql.ivazh.ru/graphql/") transport = AIOHTTPTransport(url="https://gql.ivazh.ru/graphql/")
service = 'pdim'
def get_classifier(): def get_classifier():
client = Client(transport=transport, fetch_schema_from_transport=True) client = Client(transport=transport, fetch_schema_from_transport=True, execute_timeout=None)
query = gql( query = gql(
""" """
query getClassifier { query getClassifier($name: String!) {
getClassifier(name: "ood") getClassifier(name: $name)
} }
""" """
) )
result = client.execute(query) result = client.execute(query, variable_values={"name": service}, )
return result['getClassifier'] return result['getClassifier']
def get_catalog(): def get_catalog():
client = Client(transport=transport, fetch_schema_from_transport=True) client = Client(transport=transport, fetch_schema_from_transport=True, execute_timeout=None)
query = gql( query = gql(
""" """
query getCatalog { query getCatalog($name: String!) {
getCatalog(name: "ood") getCatalog(name: $name)
} }
""" """
) )
result = client.execute(query) result = client.execute(query, variable_values={"name": service})
return result['getCatalog'] return result['getCatalog']
def get_object(oid: str): def get_object(oid: str):
client = Client(transport=transport, fetch_schema_from_transport=True) client = Client(transport=transport, fetch_schema_from_transport=True, execute_timeout=None)
query = gql( query = gql(
""" """
query getObjects($oid: String!) { query getObjects($oid: String!, $name: String!) {
getObject(name: "ood", oid: $oid) getObject(name: $name, oid: $oid)
} }
""" """
) )
params = {'oid': oid} params = {'oid': oid, 'name': service}
result = client.execute(query, variable_values=params) result = client.execute(query, variable_values=params)
return result['getObject'] return result['getObject']