#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : AI.  @by PyCharm
# @File         : common
# @Time         : 2024/11/28 15:28
# @Author       : betterme
# @WeChat       : meutils
# @Software     : PyCharm
# @Description  : 

from meutils.pipe import *
from meutils.decorators.retry import retrying

import dramatiq
from dramatiq.middleware import AsyncIO
from dramatiq.brokers.redis import RedisBroker  # 如果你用 RabbitMQ 就换成 RabbitmqBroker

from dramatiq.encoder import JSONEncoder

class PydanticJSONEncoder(JSONEncoder):
    def default(self, obj):
        if isinstance(obj, BaseModel):
            return obj.model_dump() # 或者 model_dump_json()
        return super().default(obj)



encoder = PydanticJSONEncoder()
broker = RedisBroker(url="redis://localhost:6379/0", encoder=encoder)
dramatiq.set_broker(broker)