示例#1
0
    def run(self, force=False, queues=None, exclude_queues=None, **kwargs):
        queues = set(str_to_list(queues or []))
        exclude = set(str_to_list(exclude_queues or []))
        names = (queues or set(keys(self.app.amqp.queues))) - exclude
        qnum = len(names)

        messages = None
        if names:
            if not force:
                self.out(
                    self.warn_prelude.format(
                        warning=self.colored.red('WARNING'),
                        queues=text.pluralize(qnum, 'queue'),
                        names=', '.join(sorted(names)),
                    ))
                if self.ask(self.warn_prompt, ('yes', 'no'), 'no') != 'yes':
                    return
            with self.app.connection_for_write() as conn:
                messages = sum(self._purge(conn, queue) for queue in names)
        fmt = self.fmt_purged if messages else self.fmt_empty
        self.out(
            fmt.format(mnum=messages,
                       qnum=qnum,
                       messages=text.pluralize(messages, 'message'),
                       queues=text.pluralize(qnum, 'queue')))
示例#2
0
 def setup_queues(self, include, exclude=None):
     include = str_to_list(include)
     exclude = str_to_list(exclude)
     try:
         self.app.amqp.queues.select(include)
     except KeyError as exc:
         raise ImproperlyConfigured(
             SELECT_UNKNOWN_QUEUE.strip().format(include, exc))
     try:
         self.app.amqp.queues.deselect(exclude)
     except KeyError as exc:
         raise ImproperlyConfigured(
             DESELECT_UNKNOWN_QUEUE.strip().format(exclude, exc))
     if self.app.conf.worker_direct:
         self.app.amqp.queues.select_add(worker_direct(self.hostname))
示例#3
0
文件: worker.py 项目: Scalr/celery
 def setup_queues(self, include, exclude=None):
     include = str_to_list(include)
     exclude = str_to_list(exclude)
     try:
         self.app.amqp.queues.select(include)
     except KeyError as exc:
         raise ImproperlyConfigured(
             SELECT_UNKNOWN_QUEUE.strip().format(include, exc))
     try:
         self.app.amqp.queues.deselect(exclude)
     except KeyError as exc:
         raise ImproperlyConfigured(
             DESELECT_UNKNOWN_QUEUE.strip().format(exclude, exc))
     if self.app.conf.worker_direct:
         self.app.amqp.queues.select_add(worker_direct(self.hostname))
示例#4
0
 def __init__(self,
              app,
              conn,
              filter,
              limit=None,
              timeout=1.0,
              ack_messages=False,
              tasks=None,
              queues=None,
              callback=None,
              forever=False,
              on_declare_queue=None,
              consume_from=None,
              state=None,
              accept=None,
              **kwargs):
     self.app = app
     self.conn = conn
     self.filter = filter
     self.limit = limit
     self.timeout = timeout
     self.ack_messages = ack_messages
     self.tasks = set(str_to_list(tasks) or [])
     self.queues = prepare_queues(queues)
     self.callback = callback
     self.forever = forever
     self.on_declare_queue = on_declare_queue
     self.consume_from = [
         _maybe_queue(self.app, q)
         for q in consume_from or list(self.queues)
     ]
     self.state = state or State()
     self.accept = accept
示例#5
0
    def run(self, force=False, queues=None, exclude_queues=None, **kwargs):
        queues = set(str_to_list(queues or []))
        exclude = set(str_to_list(exclude_queues or []))
        names = (queues or set(keys(self.app.amqp.queues))) - exclude
        qnum = len(names)

        messages = None
        if names:
            if not force:
                self.out(self.warn_prelude.format(
                    warning=self.colored.red('WARNING'),
                    queues=text.pluralize(qnum, 'queue'),
                    names=', '.join(sorted(names)),
                ))
                if self.ask(self.warn_prompt, ('yes', 'no'), 'no') != 'yes':
                    return
            with self.app.connection_for_write() as conn:
                messages = sum(self._purge(conn, queue) for queue in names)
        fmt = self.fmt_purged if messages else self.fmt_empty
        self.out(fmt.format(
            mnum=messages, qnum=qnum,
            messages=text.pluralize(messages, 'message'),
            queues=text.pluralize(qnum, 'queue')))
示例#6
0
    def setup_instance(self,
                       queues=None,
                       ready_callback=None,
                       pidfile=None,
                       include=None,
                       use_eventloop=None,
                       exclude_queues=None,
                       **kwargs):
        self.pidfile = pidfile
        self.setup_queues(queues, exclude_queues)
        self.setup_includes(str_to_list(include))

        # Set default concurrency
        if not self.concurrency:
            try:
                self.concurrency = cpu_count()
            except NotImplementedError:
                self.concurrency = 2

        # Options
        self.loglevel = mlevel(self.loglevel)
        self.ready_callback = ready_callback or self.on_consumer_ready

        # this connection won't establish, only used for params
        self._conninfo = self.app.connection_for_read()
        self.use_eventloop = (self.should_use_eventloop()
                              if use_eventloop is None else use_eventloop)
        self.options = kwargs

        signals.worker_init.send(sender=self)

        # Initialize bootsteps
        self.pool_cls = _concurrency.get_implementation(self.pool_cls)
        self.steps = []
        self.on_init_blueprint()
        # 创建启动蓝图
        self.blueprint = self.Blueprint(
            steps=self.app.steps['worker'],
            on_start=self.on_start,
            on_close=self.on_close,
            on_stopped=self.on_stopped,
        )
        # 创建蓝图的steps
        self.blueprint.apply(self, **kwargs)
示例#7
0
文件: worker.py 项目: Scalr/celery
    def setup_instance(self, queues=None, ready_callback=None, pidfile=None,
                       include=None, use_eventloop=None, exclude_queues=None,
                       **kwargs):
        self.pidfile = pidfile
        self.setup_queues(queues, exclude_queues)
        self.setup_includes(str_to_list(include))

        # Set default concurrency
        if not self.concurrency:
            try:
                self.concurrency = cpu_count()
            except NotImplementedError:
                self.concurrency = 2

        # Options
        self.loglevel = mlevel(self.loglevel)
        self.ready_callback = ready_callback or self.on_consumer_ready

        # this connection won't establish, only used for params
        self._conninfo = self.app.connection_for_read()
        self.use_eventloop = (
            self.should_use_eventloop() if use_eventloop is None
            else use_eventloop
        )
        self.options = kwargs

        signals.worker_init.send(sender=self)

        # Initialize bootsteps
        self.pool_cls = _concurrency.get_implementation(self.pool_cls)
        self.steps = []
        self.on_init_blueprint()
        self.blueprint = self.Blueprint(
            steps=self.app.steps['worker'],
            on_start=self.on_start,
            on_close=self.on_close,
            on_stopped=self.on_stopped,
        )
        self.blueprint.apply(self, **kwargs)
示例#8
0
文件: migrate.py 项目: tayfun/celery
 def __init__(self, app, conn, filter,
              limit=None, timeout=1.0,
              ack_messages=False, tasks=None, queues=None,
              callback=None, forever=False, on_declare_queue=None,
              consume_from=None, state=None, accept=None, **kwargs):
     self.app = app
     self.conn = conn
     self.filter = filter
     self.limit = limit
     self.timeout = timeout
     self.ack_messages = ack_messages
     self.tasks = set(str_to_list(tasks) or [])
     self.queues = prepare_queues(queues)
     self.callback = callback
     self.forever = forever
     self.on_declare_queue = on_declare_queue
     self.consume_from = [
         _maybe_queue(self.app, q)
         for q in consume_from or list(self.queues)
     ]
     self.state = state or State()
     self.accept = accept
示例#9
0
 def convert(self, value, param, ctx):
     return text.str_to_list(value)