Fix Request/Answer queries
This commit is contained in:
41
main.py
41
main.py
@@ -1,3 +1,6 @@
|
||||
import asyncio
|
||||
import threading
|
||||
from queue import Queue
|
||||
import datetime
|
||||
import json
|
||||
from uuid import uuid4, UUID
|
||||
@@ -15,6 +18,14 @@ import zipfile
|
||||
|
||||
PASSWORD = 'gost_2012$a742ec53198ec2a5027086fba8814a89982a57112d1a72d02260161108f39b50'
|
||||
|
||||
tasks = Queue()
|
||||
|
||||
|
||||
def run_tasks():
|
||||
while True:
|
||||
task = tasks.get()
|
||||
task()
|
||||
|
||||
|
||||
# Expose a function
|
||||
def list_contents(dir_name):
|
||||
@@ -45,6 +56,7 @@ def restore_uuid(oid):
|
||||
|
||||
|
||||
def load_catalog(params, files, url):
|
||||
print('load_catalog')
|
||||
date = datetime.datetime.now()
|
||||
rxmls = RequestXmlService()
|
||||
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)
|
||||
}
|
||||
catalog = get_catalog()
|
||||
print('Catalog_loaded')
|
||||
filename = uuid4().hex
|
||||
filepath = '/tmp/' + filename
|
||||
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/')
|
||||
|
||||
|
||||
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):
|
||||
print(params, files, url)
|
||||
print('Accept')
|
||||
if params['query_type'] == 4:
|
||||
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)
|
||||
run_task(params['query_type'], params, files, url)
|
||||
return True
|
||||
|
||||
|
||||
@@ -188,6 +205,9 @@ def main():
|
||||
server.register_function(accept)
|
||||
server.register_function(onSent)
|
||||
|
||||
thread = threading.Thread(target=run_tasks)
|
||||
thread.start()
|
||||
|
||||
try:
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
@@ -195,11 +215,12 @@ def main():
|
||||
|
||||
|
||||
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}
|
||||
files = []
|
||||
url = 'http://127.0.0.1:7000/xmlrpc'
|
||||
#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 = []
|
||||
#url = 'http://127.0.0.1:7000/xmlrpc'
|
||||
# accept(params, files, url)
|
||||
get_metadata(params, files, url)
|
||||
#get_metadata(params, files, url)
|
||||
get_catalog()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -2,43 +2,44 @@ from gql import gql, Client
|
||||
from gql.transport.aiohttp import AIOHTTPTransport
|
||||
|
||||
transport = AIOHTTPTransport(url="https://gql.ivazh.ru/graphql/")
|
||||
service = 'pdim'
|
||||
|
||||
|
||||
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 getClassifier {
|
||||
getClassifier(name: "ood")
|
||||
query getClassifier($name: String!) {
|
||||
getClassifier(name: $name)
|
||||
}
|
||||
"""
|
||||
)
|
||||
result = client.execute(query)
|
||||
result = client.execute(query, variable_values={"name": service}, )
|
||||
return result['getClassifier']
|
||||
|
||||
|
||||
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 getCatalog {
|
||||
getCatalog(name: "ood")
|
||||
query getCatalog($name: String!) {
|
||||
getCatalog(name: $name)
|
||||
}
|
||||
"""
|
||||
)
|
||||
result = client.execute(query)
|
||||
result = client.execute(query, variable_values={"name": service})
|
||||
return result['getCatalog']
|
||||
|
||||
|
||||
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 getObjects($oid: String!) {
|
||||
getObject(name: "ood", oid: $oid)
|
||||
query getObjects($oid: String!, $name: String!) {
|
||||
getObject(name: $name, oid: $oid)
|
||||
}
|
||||
"""
|
||||
)
|
||||
params = {'oid': oid}
|
||||
params = {'oid': oid, 'name': service}
|
||||
result = client.execute(query, variable_values=params)
|
||||
return result['getObject']
|
||||
|
||||
Reference in New Issue
Block a user