def _shedual_task(self):
     mp = MongoMqPublisher(self.queue_name)
     while True:
         job = mp.queue.next()
         if job is not None:
             self.logger.debug(f'从mongo的 [{self._queue_name}] 队列中 取出的消息是:   消息是:  {job.payload}  ')
             kw = {'body': job.payload, 'job': job}
             self._submit_task(kw)
         else:
             time.sleep(0.1)
Ejemplo n.º 2
0
 def _shedual_task(self):
     mp = MongoMqPublisher(self.queue_name)
     while True:
         t_start = time.time()
         job = mp.queue.next()
         if job is not None:
             self.logger.debug(
                 f'取出的任务时间是 {round(time.time() - t_start, 4)}    消息是:  {job.payload}  '
             )
             kw = {'body': job.payload, 'job': job}
             self._submit_task(kw)
         else:
             time.sleep(self._msg_schedule_time_intercal)
Ejemplo n.º 3
0
def get_publisher(queue_name,
                  *,
                  log_level_int=10,
                  logger_prefix='',
                  is_add_file_handler=True,
                  clear_queue_within_init=False,
                  is_add_publish_time=True,
                  consuming_function: Callable = None,
                  broker_kind=0):
    """
    :param queue_name:
    :param log_level_int:
    :param logger_prefix:
    :param is_add_file_handler:
    :param clear_queue_within_init:
    :param is_add_publish_time:是否添加发布时间,以后废弃,都添加。
    :param is_using_rpc_mode:是否使用rpc模式,发布端将可以获取消费端的结果。需要安装redis和额外的性能。
    :param consuming_function:消费函数,为了做发布时候的函数入参校验用的,如果不传则不做发布任务的校验,
               例如add 函数接收x,y入参,你推送{"x":1,"z":3}就是不正确的,函数不接受z参数。
    :param broker_kind: 中间件或使用包的种类。
    :return:
    """
    all_kwargs = copy.deepcopy(locals())
    all_kwargs.pop('broker_kind')
    if broker_kind == 0:
        return RabbitmqPublisher(**all_kwargs)
    elif broker_kind == 1:
        return RabbitmqPublisherUsingRabbitpy(**all_kwargs)
    elif broker_kind == 2:
        return RedisPublisher(**all_kwargs)
    elif broker_kind == 3:
        return LocalPythonQueuePublisher(**all_kwargs)
    elif broker_kind == 4:
        return RabbitmqPublisherUsingAmqpStorm(**all_kwargs)
    elif broker_kind == 5:
        return MongoMqPublisher(**all_kwargs)
    elif broker_kind == 6:
        return PersistQueuePublisher(**all_kwargs)
    elif broker_kind == 7:
        return NsqPublisher(**all_kwargs)
    elif broker_kind == 8:
        return KafkaPublisher(**all_kwargs)
    elif broker_kind == 9:
        return RedisPublisher(**all_kwargs)
    elif broker_kind == 10:
        return SqlachemyQueuePublisher(**all_kwargs)
    else:
        raise ValueError('设置的中间件种类数字不正确')
def get_publisher(queue_name,
                  *,
                  log_level_int=10,
                  logger_prefix='',
                  is_add_file_handler=True,
                  clear_queue_within_init=False,
                  is_add_publish_time=True,
                  is_using_rpc_mode=False,
                  broker_kind=0):
    """
    :param queue_name:
    :param log_level_int:
    :param logger_prefix:
    :param is_add_file_handler:
    :param clear_queue_within_init:
    :param is_add_publish_time:是否添加发布时间,以后废弃,都添加。
    :param is_using_rpc_mode:是否使用rpc模式,发布端将可以获取消费端的结果。需要安装redis和额外的性能。
    :param broker_kind: 中间件或使用包的种类。
    :return:
    """
    all_kwargs = copy.deepcopy(locals())
    all_kwargs.pop('broker_kind')
    if broker_kind == 0:
        return RabbitmqPublisher(**all_kwargs)
    elif broker_kind == 1:
        return RabbitmqPublisherUsingRabbitpy(**all_kwargs)
    elif broker_kind == 2:
        return RedisPublisher(**all_kwargs)
    elif broker_kind == 3:
        return LocalPythonQueuePublisher(**all_kwargs)
    elif broker_kind == 4:
        return RabbitmqPublisherUsingAmqpStorm(**all_kwargs)
    elif broker_kind == 5:
        return MongoMqPublisher(**all_kwargs)
    elif broker_kind == 6:
        return PersistQueuePublisher(**all_kwargs)
    elif broker_kind == 7:
        return NsqPublisher(**all_kwargs)
    elif broker_kind == 8:
        return KafkaPublisher(**all_kwargs)
    elif broker_kind == 9:
        return RedisPublisher(**all_kwargs)
    else:
        raise ValueError('设置的中间件种类数字不正确')
def get_publisher(queue_name,
                  *,
                  log_level_int=10,
                  logger_prefix='',
                  is_add_file_handler=False,
                  clear_queue_within_init=False,
                  is_add_publish_time=False,
                  broker_kind=0):
    """
    :param queue_name:
    :param log_level_int:
    :param logger_prefix:
    :param is_add_file_handler:
    :param clear_queue_within_init:
    :param is_add_publish_time:是否添加发布时间到中间件,如果设置了过期时间不为0,需要设为True
    :param broker_kind: 中间件或使用包的种类。
    :return:
    """
    all_kwargs = copy.deepcopy(locals())
    all_kwargs.pop('broker_kind')
    if broker_kind == 0:
        return RabbitmqPublisher(**all_kwargs)
    elif broker_kind == 1:
        return RabbitmqPublisherUsingRabbitpy(**all_kwargs)
    elif broker_kind == 2:
        return RedisPublisher(**all_kwargs)
    elif broker_kind == 3:
        return LocalPythonQueuePublisher(**all_kwargs)
    elif broker_kind == 4:
        return RabbitmqPublisherUsingAmqpStorm(**all_kwargs)
    elif broker_kind == 5:
        return MongoMqPublisher(**all_kwargs)
    elif broker_kind == 6:
        return PersistQueuePublisher(**all_kwargs)
    else:
        raise ValueError('设置的中间件种类数字不正确')