コード例 #1
0
ファイル: scheduler.py プロジェクト: ComeBertrand/remoulade
    def __init__(self,
                 broker: Broker,
                 schedule: List[ScheduledJob],
                 *,
                 namespace: str = None,
                 lock_key: str = None,
                 period: Union[int, float] = None,
                 client: redis.Redis = None,
                 url: str = None,
                 **redis_parameters):
        """
        The class that takes care of scheduling tasks
        :param broker: The broker for the remoulade app
        :param schedule: A map that gives the schedule you want to be running
        :param namespace: Where we should store our scheduled tasks on redis
        :param lock_key: The redis key that we use as a lock to make sure only one scheduler is working at a time
        :param period: At which period (in seconds) the scheduler should be running, default is 1 second
        :param client: The redis client we should use to access redis
        :param url: The URL of the redis client
        :param redis_parameters: Additional params to pass to redis
        """
        self.schedule = schedule
        self.namespace = namespace if namespace is not None else DEFAULT_SCHEDULER_NAMESPACE
        self.period = period if period is not None else DEFAULT_SCHEDULER_PERIOD
        self.broker = broker
        self.lock_key = lock_key if lock_key is not None else DEFAULT_SCHEDULER_LOCK_KEY

        if url:
            redis_parameters[
                "connection_pool"] = redis.ConnectionPool.from_url(url)

        self.client = client or redis.Redis(**redis_parameters)
        self.logger = get_logger(__name__, type(self))
コード例 #2
0
def setup_worker_logging(args, worker_id, logging_pipe):
    # Redirect all output to the logging pipe so that all output goes
    # to stderr and output is serialized so there isn't any mangling.
    sys.stdout = logging_pipe
    sys.stderr = logging_pipe

    level = verbosity.get(args.verbose, logging.DEBUG)
    logging.basicConfig(level=level, format=logformat, stream=logging_pipe)
    return get_logger("remoulade", "WorkerProcess(%s)" % worker_id)
コード例 #3
0
def main():

    args = parse_arguments()

    for path in args.path:
        sys.path.insert(0, path)

    for module in args.modules:
        importlib.import_module(module)

    logging.basicConfig(
        level=logging.INFO if not args.verbose else logging.DEBUG,
        format=logformat)
    logger = get_logger("remoulade", "Scheduler")

    def signal_handler(signal, frame):
        logger.debug('Remoulade scheduler is shutting down')
        sys.exit(0)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    logger.debug("Remoulade scheduler start")
    sys.exit(get_scheduler().start())
コード例 #4
0
def setup_parent_logging(args, *, stream=sys.stderr):
    level = verbosity.get(args.verbose, logging.DEBUG)
    logging.basicConfig(level=level, format=logformat, stream=stream)
    return get_logger("remoulade", "MainProcess")