Fix connections
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from json import JSONDecodeError
|
||||
from tempfile import TemporaryDirectory, gettempdir
|
||||
from typing import Optional, Any
|
||||
|
||||
@@ -69,31 +70,35 @@ def restore_uuid(oid):
|
||||
|
||||
|
||||
def pika_callback(ch, method, properties, body):
|
||||
data = json.loads(body)
|
||||
params = data['params']
|
||||
url = data['url']
|
||||
files = []
|
||||
for file in params['files']:
|
||||
fn = os.path.join(gettempdir(), uuid4().hex)
|
||||
download_file(file['name'], file['bucket'], fn)
|
||||
files.append(fn)
|
||||
run_task(params['query_type'], params, files, url)
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
try:
|
||||
data = json.loads(body)
|
||||
params = data['params']
|
||||
url = data['url']
|
||||
files = []
|
||||
for file in data['files']:
|
||||
fn = os.path.join(gettempdir(), uuid4().hex)
|
||||
download_file(file['name'], file['bucket'], fn)
|
||||
files.append(fn)
|
||||
run_task(params['query_type'], params, files, url)
|
||||
# except JSONDecodeError as e:
|
||||
# logging.warning(e)
|
||||
finally:
|
||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||
|
||||
|
||||
def send_response(params, files, url):
|
||||
global channel_send
|
||||
files_s3 = []
|
||||
for file in params['files']:
|
||||
for file in files:
|
||||
fn = uuid4().hex
|
||||
upload_file(file, fn, Config.s3_bucket)
|
||||
upload_file(file['url'], fn, Config.s3_bucket)
|
||||
files_s3.append({'name': fn, 'bucket': Config.s3_bucket})
|
||||
data = {
|
||||
'params': params,
|
||||
'files': files_s3,
|
||||
'url': url,
|
||||
}
|
||||
channel_send.basic_publish(exchange=Config.rabbit_out_exchange, body=json.dumps(data))
|
||||
channel_send.basic_publish(exchange=Config.rabbit_out_exchange, body=json.dumps(data), routing_key='')
|
||||
|
||||
|
||||
def pika_task():
|
||||
@@ -267,13 +272,13 @@ def put_object(params, files, url):
|
||||
|
||||
def run_task(query_type, params, files, url):
|
||||
if query_type == 4:
|
||||
tasks.put(lambda: load_catalog(params, files, url))
|
||||
load_catalog(params, files, url)
|
||||
if query_type == 1:
|
||||
tasks.put(lambda: get_objects(params, files, url))
|
||||
get_objects(params, files, url)
|
||||
if query_type == 24:
|
||||
tasks.put(lambda: get_metadata(params, files, url))
|
||||
get_metadata(params, files, url)
|
||||
if query_type == 6:
|
||||
tasks.put(lambda: put_object(params, files, url))
|
||||
put_object(params, files, url)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user