2024-09-12 10:06:25 +08:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
import pika
|
|
|
|
|
|
2024-09-26 14:12:17 +08:00
|
|
|
from app.service.design_batch.design_batch import batch_design
|
2024-09-12 10:06:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def publish_status(task_id, progress, result):
|
|
|
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
|
|
|
|
|
channel = connection.channel()
|
|
|
|
|
channel.queue_declare(queue='DesignBatch', durable=True)
|
|
|
|
|
message = {'task_id': task_id, 'progress': progress, "result": result}
|
|
|
|
|
print(message)
|
|
|
|
|
channel.basic_publish(exchange='',
|
|
|
|
|
routing_key='DesignBatch',
|
|
|
|
|
body=json.dumps(message),
|
|
|
|
|
properties=pika.BasicProperties(
|
|
|
|
|
delivery_mode=2,
|
|
|
|
|
))
|
|
|
|
|
connection.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def start_design_batch_generate(data, file):
|
2024-09-26 14:12:17 +08:00
|
|
|
generate_clothes_task = batch_design.delay(json.loads(file.decode())['objects'], data.total, data.tasks_id)
|
2024-09-12 10:06:25 +08:00
|
|
|
print(generate_clothes_task)
|
|
|
|
|
publish_status(data.tasks_id, "0/100", "")
|
|
|
|
|
return {"task_id": data.tasks_id}
|