# -*- coding: utf-8 -*-
import time
from threading import Thread
from loguru import logger
from util import KafkaUtils

'''
    问题反馈线程
'''


class FeedbackThread(Thread):

    def __init__(self, fbQueue, content):
        super().__init__()
        self.fbQueue = fbQueue
        self.content = content

    def getFeedback(self):
        return self.fbQueue.get()

    def run(self):
        logger.info("启动问题反馈线程")
        kafkaProducer = KafkaUtils.CustomerKafkaProducer(self.content)
        while True:
            logger.info("问题反馈发送消息循环")
            fb = {}
            try:
                fb = self.getFeedback()
                if fb is not None and len(fb) > 0:
                    kafkaProducer.sender(self.content["kafka"]["topic"]["fk-alg-results-topic"],
                                         fb["msgId"], fb, 1)
                else:
                    time.sleep(1)
            except Exception as e:
                logger.exception("问题反馈异常：{}, msgId:{}", e, fb.get("msgId"))
        logger.info("问题反馈进程执行完成")
