示例#1
0
def demo_controller(urls):
    for url in urls:
        scheduler_controller_queue(url)
    task_queue = RedisMsgQueue()
    controller_worker = Controller(
        consts.constant_manager.CONTROLLER_QUEUE_NAME, task_queue, 1)
    controller_worker.start()
    controller_worker.wait()
    task_queue.addQueue(consts.constant_manager.DOWNLOAD_QUEUE_NAME, 20480)
    task_queue.addQueue('demo', 20480)
    # downloader_worker = Downloader(consts.constant_manager.DOWNLOAD_QUEUE_NAME, task_queue, 1)
    # downloader_worker.start()
    # downloader_worker.wait()
    downloader_worker = Downloader('demo', task_queue, 1)
    downloader_worker.start()
    downloader_worker.wait()
    # task_queue = RedisMsgQueue()
    # controller_worker = Controller(consts.constant_manager.CONTROLLER_QUEUE_NAME, task_queue, 1)
    # controller_worker.start()
    while True:
        logging.info(
            "=================> queue_size: %d",
            task_queue.size(consts.constant_manager.CONTROLLER_QUEUE_NAME))
        time.sleep(10)
    pass
示例#2
0
def scheduler_download_status_queue(download_file_status_json):
    redis_queue = RedisMsgQueue()
    redis_queue.addQueue(consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME, 1)
    redis_queue.set_add(consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME,
                        from_json_to_string(download_file_status_json))
    logging.debug('push download_file_status hash_sign %s' %
                  download_file_status_json['hash_sign'])
    pass
示例#3
0
文件: scheduler.py 项目: yangge11/ant
def scheduler_controller_queue(url):
    try:
        task_queue = RedisMsgQueue()
        task_queue.addQueue(consts.constant_manager.CONTROLLER_QUEUE_NAME, 1)
        task_queue.push(consts.constant_manager.CONTROLLER_QUEUE_NAME, url)
        logging.debug('push task url %s' % url)
    except:
        traceback.print_exc()
        logging.error('push task error')
示例#4
0
def run():
    task_queue = RedisMsgQueue()
    task_queue.addQueue(consts.constant_manager.CONTROLLER_QUEUE_NAME, 20480)
    controller_worker = Controller(consts.constant_manager.CONTROLLER_QUEUE_NAME, task_queue, 10)
    controller_worker.start()

    while True:
        logging.info("=================> queue_size: %d", task_queue.size(consts.constant_manager.CONTROLLER_QUEUE_NAME))
        time.sleep(10)
示例#5
0
def run(queue_name):
    task_queue = RedisMsgQueue()
    task_queue.addQueue(queue_name, 20480)
    downloader_worker = Downloader(queue_name, task_queue, 10)
    downloader_worker.start()

    while True:
        logging.info("queue_name %s==========> queue_size: %d" %
                     (queue_name, task_queue.size(queue_name)))
        time.sleep(10)
示例#6
0
文件: scheduler.py 项目: yangge11/ant
def scheduler_download_queue(download_file_json, priority=False):
    redis_queue = RedisMsgQueue()
    redis_queue.addQueue(consts.constant_manager.DOWNLOAD_QUEUE_NAME, 1)
    if priority:
        redis_queue.l_push(consts.constant_manager.DOWNLOAD_QUEUE_NAME, from_json_to_string(download_file_json))
    else:
        # todo:下载任务细粒度管理
        redis_queue.push('demo', from_json_to_string(download_file_json))
    logging.debug('push download_file download_url %s' % download_file_json['download_url'])
    pass
示例#7
0
def run():
    task_queue = RedisMsgQueue()
    task_queue.addQueue(consts.constant_manager.DB_SAVE_QUEUE_NAME, 20480)
    db_save_worker = DBSaveWorker(consts.constant_manager.DB_SAVE_QUEUE_NAME,
                                  task_queue, 3)
    db_save_worker.start()

    while True:
        logging.info(
            "=================> queue_size: %d",
            task_queue.size(consts.constant_manager.DB_SAVE_QUEUE_NAME))
        time.sleep(10)
示例#8
0
def run():
    task_queue = RedisMsgQueue()
    task_queue.addQueue(consts.constant_manager.DOWNLOAD_QUEUE_NAME, 20480)
    downloader_worker = Downloader(consts.constant_manager.DOWNLOAD_QUEUE_NAME,
                                   task_queue, 3)
    downloader_worker.start()

    while True:
        logging.info(
            "=================> queue_size: %d",
            task_queue.size(consts.constant_manager.DOWNLOAD_QUEUE_NAME))
        time.sleep(10)
示例#9
0
def demo_worker_exception():
    task_queue = RedisMsgQueue()
    task_queue.addQueue(consts.constant_manager.CONTROLLER_QUEUE_NAME, 20480)
    for i in range(1, 100):
        task_queue.push(consts.constant_manager.CONTROLLER_QUEUE_NAME,
                        'asdasdas')
    worker = Worker(consts.constant_manager.CONTROLLER_QUEUE_NAME, task_queue,
                    3)
    worker.start()
    while True:
        print 'demo'
        time.sleep(30)
    pass
示例#10
0
文件: my_demo.py 项目: blankxyz/ant
def demo_controller(urls):
    for url in urls:
        scheduler_controller_queue(url)
        task_queue = RedisMsgQueue()
        controller_worker = Controller(
            consts.constant_manager.CONTROLLER_QUEUE_NAME, task_queue, 3)
        controller_worker.start()
        controller_worker.wait()
        task_queue.addQueue(consts.constant_manager.DOWNLOAD_QUEUE_NAME, 20480)
        downloader_worker = Downloader(
            consts.constant_manager.DOWNLOAD_QUEUE_NAME, task_queue, 3)
        downloader_worker.start()
        downloader_worker.wait()
        # task_queue.addQueue(consts.constant_manager.DB_SAVE_QUEUE_NAME, 20480)
        # db_save_worker = DBSaveWorker(consts.constant_manager.DB_SAVE_QUEUE_NAME, task_queue, 3)
        # db_save_worker.start()
        # db_save_worker.wait()
    pass
示例#11
0
def scheduler_controller_queue(url):
    task_queue = RedisMsgQueue()
    task_queue.addQueue(consts.constant_manager.CONTROLLER_QUEUE_NAME, 1)
    task_queue.push(consts.constant_manager.CONTROLLER_QUEUE_NAME, url)
    logging.debug('push task url %s' % url)
示例#12
0
文件: scheduler.py 项目: yangge11/ant
def scheduler_download_status_queue(download_file_status_json):
    redis_queue = RedisMsgQueue()
    redis_queue.addQueue(consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME, 1)
    redis_queue.hash_set(consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME, download_file_status_json['hash_sign'],
                         from_json_to_string(download_file_status_json))
    pass