#!/usr/bin/env python2.7
# coding: utf-8
import logging
import os
import sys
from logging.config import dictConfig
from multiprocessing import active_children
from time import sleep
from lib import utils

from lib.utils import (check_network_status, create_pidfile, daemonize,
                       load_config_from_pyfile, parse_cmd_args, spawn_workers)
from lib.worker import worker
from tests import my_mocked_method_for_test

logger = logging.getLogger('redirect_checker')

def condition_is_true():
    return True

def create_workers(config, parent_pid):
    required_workers_count = config.WORKER_POOL_SIZE - len(
        active_children())
    if required_workers_count > 0:
        logger.info(
            'Spawning {} workers'.format(required_workers_count))
        spawn_workers(
            num=required_workers_count,
            target=worker,
            args=(config,),
            parent_pid=parent_pid
        )
    else:
        my_mocked_method_for_test('full_pool')

def remove_workers():
    logger.critical('Network is down. stopping workers')
    for c in active_children():
        c.terminate()

def main_loop(config):
    logger.info(
        u'Run main loop. Worker pool size={}. Sleep time is {}.'.format(
            config.WORKER_POOL_SIZE, config.SLEEP
        ))
    parent_pid = os.getpid()
    while condition_is_true():
        if check_network_status(config.CHECK_URL, config.HTTP_TIMEOUT):
            create_workers(config, parent_pid)
        else:
            remove_workers()

        sleep(config.SLEEP)


def main(argv):
    args = parse_cmd_args(argv[1:])

    config = utils.get_config_with_args(args)
    main_loop(config)

    return config.EXIT_CODE


if __name__ == '__main__':
    sys.exit(main(sys.argv))

16b17def83f4b0c669bbd0f54183403f81bb4221
<mask token>


def condition_is_true():
    return True


def create_workers(config, parent_pid):
    required_workers_count = config.WORKER_POOL_SIZE - len(active_children())
    if required_workers_count > 0:
        logger.info('Spawning {} workers'.format(required_workers_count))
        spawn_workers(num=required_workers_count, target=worker, args=(
            config,), parent_pid=parent_pid)
    else:
        my_mocked_method_for_test('full_pool')


def remove_workers():
    logger.critical('Network is down. stopping workers')
    for c in active_children():
        c.terminate()


<mask token>


def main(argv):
    args = parse_cmd_args(argv[1:])
    config = utils.get_config_with_args(args)
    main_loop(config)
    return config.EXIT_CODE


<mask token>

<mask token>


def condition_is_true():
    return True


def create_workers(config, parent_pid):
    required_workers_count = config.WORKER_POOL_SIZE - len(active_children())
    if required_workers_count > 0:
        logger.info('Spawning {} workers'.format(required_workers_count))
        spawn_workers(num=required_workers_count, target=worker, args=(
            config,), parent_pid=parent_pid)
    else:
        my_mocked_method_for_test('full_pool')


def remove_workers():
    logger.critical('Network is down. stopping workers')
    for c in active_children():
        c.terminate()


def main_loop(config):
    logger.info(u'Run main loop. Worker pool size={}. Sleep time is {}.'.
        format(config.WORKER_POOL_SIZE, config.SLEEP))
    parent_pid = os.getpid()
    while condition_is_true():
        if check_network_status(config.CHECK_URL, config.HTTP_TIMEOUT):
            create_workers(config, parent_pid)
        else:
            remove_workers()
        sleep(config.SLEEP)


def main(argv):
    args = parse_cmd_args(argv[1:])
    config = utils.get_config_with_args(args)
    main_loop(config)
    return config.EXIT_CODE


if __name__ == '__main__':
    sys.exit(main(sys.argv))

<mask token>
logger = logging.getLogger('redirect_checker')


def condition_is_true():
    return True


def create_workers(config, parent_pid):
    required_workers_count = config.WORKER_POOL_SIZE - len(active_children())
    if required_workers_count > 0:
        logger.info('Spawning {} workers'.format(required_workers_count))
        spawn_workers(num=required_workers_count, target=worker, args=(
            config,), parent_pid=parent_pid)
    else:
        my_mocked_method_for_test('full_pool')


def remove_workers():
    logger.critical('Network is down. stopping workers')
    for c in active_children():
        c.terminate()


def main_loop(config):
    logger.info(u'Run main loop. Worker pool size={}. Sleep time is {}.'.
        format(config.WORKER_POOL_SIZE, config.SLEEP))
    parent_pid = os.getpid()
    while condition_is_true():
        if check_network_status(config.CHECK_URL, config.HTTP_TIMEOUT):
            create_workers(config, parent_pid)
        else:
            remove_workers()
        sleep(config.SLEEP)


def main(argv):
    args = parse_cmd_args(argv[1:])
    config = utils.get_config_with_args(args)
    main_loop(config)
    return config.EXIT_CODE


if __name__ == '__main__':
    sys.exit(main(sys.argv))

import logging
import os
import sys
from logging.config import dictConfig
from multiprocessing import active_children
from time import sleep
from lib import utils
from lib.utils import check_network_status, create_pidfile, daemonize, load_config_from_pyfile, parse_cmd_args, spawn_workers
from lib.worker import worker
from tests import my_mocked_method_for_test
logger = logging.getLogger('redirect_checker')


def condition_is_true():
    return True


def create_workers(config, parent_pid):
    required_workers_count = config.WORKER_POOL_SIZE - len(active_children())
    if required_workers_count > 0:
        logger.info('Spawning {} workers'.format(required_workers_count))
        spawn_workers(num=required_workers_count, target=worker, args=(
            config,), parent_pid=parent_pid)
    else:
        my_mocked_method_for_test('full_pool')


def remove_workers():
    logger.critical('Network is down. stopping workers')
    for c in active_children():
        c.terminate()


def main_loop(config):
    logger.info(u'Run main loop. Worker pool size={}. Sleep time is {}.'.
        format(config.WORKER_POOL_SIZE, config.SLEEP))
    parent_pid = os.getpid()
    while condition_is_true():
        if check_network_status(config.CHECK_URL, config.HTTP_TIMEOUT):
            create_workers(config, parent_pid)
        else:
            remove_workers()
        sleep(config.SLEEP)


def main(argv):
    args = parse_cmd_args(argv[1:])
    config = utils.get_config_with_args(args)
    main_loop(config)
    return config.EXIT_CODE


if __name__ == '__main__':
    sys.exit(main(sys.argv))

#!/usr/bin/env python2.7
# coding: utf-8
import logging
import os
import sys
from logging.config import dictConfig
from multiprocessing import active_children
from time import sleep
from lib import utils

from lib.utils import (check_network_status, create_pidfile, daemonize,
                       load_config_from_pyfile, parse_cmd_args, spawn_workers)
from lib.worker import worker
from tests import my_mocked_method_for_test

logger = logging.getLogger('redirect_checker')

def condition_is_true():
    return True

def create_workers(config, parent_pid):
    required_workers_count = config.WORKER_POOL_SIZE - len(
        active_children())
    if required_workers_count > 0:
        logger.info(
            'Spawning {} workers'.format(required_workers_count))
        spawn_workers(
            num=required_workers_count,
            target=worker,
            args=(config,),
            parent_pid=parent_pid
        )
    else:
        my_mocked_method_for_test('full_pool')

def remove_workers():
    logger.critical('Network is down. stopping workers')
    for c in active_children():
        c.terminate()

def main_loop(config):
    logger.info(
        u'Run main loop. Worker pool size={}. Sleep time is {}.'.format(
            config.WORKER_POOL_SIZE, config.SLEEP
        ))
    parent_pid = os.getpid()
    while condition_is_true():
        if check_network_status(config.CHECK_URL, config.HTTP_TIMEOUT):
            create_workers(config, parent_pid)
        else:
            remove_workers()

        sleep(config.SLEEP)


def main(argv):
    args = parse_cmd_args(argv[1:])

    config = utils.get_config_with_args(args)
    main_loop(config)

    return config.EXIT_CODE


if __name__ == '__main__':
    sys.exit(main(sys.argv))
