design design batch

This commit is contained in:
zhouchengrong
2024-12-11 14:40:58 +08:00
parent 84fe2663f4
commit be16c95faa
4 changed files with 7 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ from app.service.design_batch.utils.save_json import oss_upload_json
from app.service.design_batch.utils.synthesis_item import update_base_size_priority, synthesis, synthesis_single from app.service.design_batch.utils.synthesis_item import update_base_size_priority, synthesis, synthesis_single
id_lock = threading.Lock() id_lock = threading.Lock()
celery_app = Celery('tasks', broker='amqp://guest:guest@10.1.2.213:5672//', backend='rpc://') celery_app = Celery('tasks', broker=f'amqp://rabbit:123456@18.167.251.121:5672//', backend='rpc://', BROKER_CONNECTION_RETRY_ON_STARTUP=True)
celery_app.conf.worker_log_format = '%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s %(message)s' celery_app.conf.worker_log_format = '%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s %(message)s'
celery_app.conf.worker_hijack_root_logger = False celery_app.conf.worker_hijack_root_logger = False
logging.getLogger('pika').setLevel(logging.WARNING) logging.getLogger('pika').setLevel(logging.WARNING)
@@ -120,7 +120,7 @@ def batch_design(objects_data, tasks_id, json_name):
for t in threads: for t in threads:
t.join() t.join()
logger.debug(object_response)
oss_upload_json(minio_client, object_response, json_name) oss_upload_json(minio_client, object_response, json_name)
publish_status(tasks_id, "ok", json_name) publish_status(tasks_id, "ok", json_name)
return object_response return object_response

View File

@@ -5,7 +5,7 @@ from app.service.design_batch.utils.MQ import publish_status
async def start_design_batch_generate(data, file): async def start_design_batch_generate(data, file):
generate_clothes_task = batch_design.delay(json.loads(file.decode())['objects'], data.total, data.tasks_id) generate_clothes_task = batch_design.delay(json.loads(file.decode())['objects'], data.tasks_id, data.file_name)
print(generate_clothes_task) print(generate_clothes_task)
publish_status(data.tasks_id, "0/100", "") publish_status(data.tasks_id, "0/100", "")
return {"task_id": data.tasks_id} return {"task_id": data.tasks_id}

View File

@@ -157,6 +157,6 @@ if __name__ == '__main__':
], ],
"process_id": "83" "process_id": "83"
} }
task_id = 1 task_id = 10086
json_name = "test.json" json_name = "test.json"
batch_design.delay(data['objects'], task_id, json_name) batch_design.delay(data['objects'], task_id, json_name)

View File

@@ -2,9 +2,11 @@ import json
import pika import pika
from app.core.config import RABBITMQ_PARAMS
def publish_status(task_id, progress, result): def publish_status(task_id, progress, result):
connection = pika.BlockingConnection(pika.ConnectionParameters('10.1.2.213')) connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
channel = connection.channel() channel = connection.channel()
channel.queue_declare(queue='DesignBatch', durable=True) channel.queue_declare(queue='DesignBatch', durable=True)
message = {'task_id': task_id, 'progress': progress, "result": result} message = {'task_id': task_id, 'progress': progress, "result": result}