Пример #1
0
    def __init__(self,
                 hostname=None,
                 discard=False,
                 embed_clockservice=False,
                 queues=None,
                 include=None,
                 app=None,
                 pidfile=None,
                 autoscale=None,
                 autoreload=False,
                 **kwargs):
        self.app = app = app_or_default(app or self.app)
        self.hostname = hostname or socket.gethostname()

        # this signal can be used to set up configuration for
        # workers by name.
        signals.celeryd_init.send(sender=self.hostname,
                                  instance=self,
                                  conf=self.app.conf)

        self.setup_defaults(kwargs, namespace="celeryd")
        if not self.concurrency:
            try:
                self.concurrency = cpu_count()
            except NotImplementedError:
                self.concurrency = 2
        self.discard = discard
        self.embed_clockservice = embed_clockservice
        if self.app.IS_WINDOWS and self.embed_clockservice:
            self.die("-B option does not work on Windows.  "
                     "Please run celerybeat as a separate service.")
        self.use_queues = [] if queues is None else queues
        self.queues = None
        self.include = [] if include is None else include
        self.pidfile = pidfile
        self.autoscale = None
        self.autoreload = autoreload
        if autoscale:
            max_c, _, min_c = autoscale.partition(",")
            self.autoscale = [int(max_c), min_c and int(min_c) or 0]
        self._isatty = isatty(sys.stdout)

        self.colored = app.log.colored(self.logfile)

        if isinstance(self.use_queues, basestring):
            self.use_queues = self.use_queues.split(",")
        if isinstance(self.include, basestring):
            self.include = self.include.split(",")

        try:
            self.loglevel = mlevel(self.loglevel)
        except KeyError:
            self.die("Unknown level %r. Please use one of %s." %
                     (self.loglevel, "|".join(l for l in LOG_LEVELS.keys()
                                              if isinstance(l, basestring))))
Пример #2
0
 def run(self, *args, **kwargs):
     kwargs.pop("app", None)
     # Pools like eventlet/gevent needs to patch libs as early
     # as possible.
     kwargs["pool_cls"] = concurrency.get_implementation(
                 kwargs.get("pool_cls") or self.app.conf.CELERYD_POOL)
     if self.app.IS_WINDOWS and kwargs.get("beat"):
         self.die("-B option does not work on Windows.  "
                  "Please run celerybeat as a separate service.")
     loglevel = kwargs.get("loglevel")
     if loglevel:
         try:
             kwargs["loglevel"] = mlevel(loglevel)
         except KeyError:  # pragma: no cover
             self.die("Unknown level %r. Please use one of %s." % (
                 loglevel, "|".join(l for l in LOG_LEVELS.keys()
                   if isinstance(l, basestring))))
     return self.app.Worker(**kwargs).run()
Пример #3
0
 def run(self, *args, **kwargs):
     kwargs.pop('app', None)
     # Pools like eventlet/gevent needs to patch libs as early
     # as possible.
     kwargs['pool_cls'] = concurrency.get_implementation(
                 kwargs.get('pool_cls') or self.app.conf.CELERYD_POOL)
     if self.app.IS_WINDOWS and kwargs.get('beat'):
         self.die('-B option does not work on Windows.  '
                  'Please run celerybeat as a separate service.')
     loglevel = kwargs.get('loglevel')
     if loglevel:
         try:
             kwargs['loglevel'] = mlevel(loglevel)
         except KeyError:  # pragma: no cover
             self.die('Unknown level {0!r}. Please use one of {1}.'.format(
                 loglevel, '|'.join(l for l in LOG_LEVELS.keys()
                   if isinstance(l, basestring))))
     return self.app.Worker(**kwargs).run()
Пример #4
0
 def run(self, *args, **kwargs):
     kwargs.pop("app", None)
     # Pools like eventlet/gevent needs to patch libs as early
     # as possible.
     kwargs["pool_cls"] = concurrency.get_implementation(
         kwargs.get("pool_cls") or self.app.conf.CELERYD_POOL)
     if self.app.IS_WINDOWS and kwargs.get("beat"):
         self.die("-B option does not work on Windows.  "
                  "Please run celerybeat as a separate service.")
     loglevel = kwargs.get("loglevel")
     if loglevel:
         try:
             kwargs["loglevel"] = mlevel(loglevel)
         except KeyError:  # pragma: no cover
             self.die("Unknown level %r. Please use one of %s." %
                      (loglevel, "|".join(l for l in LOG_LEVELS.keys()
                                          if isinstance(l, basestring))))
     return self.app.Worker(**kwargs).run()
Пример #5
0
    def __init__(self, hostname=None, discard=False, embed_clockservice=False,
            queues=None, include=None, app=None, pidfile=None,
            autoscale=None, autoreload=False, **kwargs):
        self.app = app = app_or_default(app or self.app)
        self.hostname = hostname or socket.gethostname()

        # this signal can be used to set up configuration for
        # workers by name.
        signals.celeryd_init.send(sender=self.hostname, instance=self,
                                  conf=self.app.conf)

        self.setup_defaults(kwargs, namespace="celeryd")
        if not self.concurrency:
            self.concurrency = cpu_count()
        self.discard = discard
        self.embed_clockservice = embed_clockservice
        if self.app.IS_WINDOWS and self.embed_clockservice:
            self.die("-B option does not work on Windows.  "
                     "Please run celerybeat as a separate service.")
        self.use_queues = [] if queues is None else queues
        self.queues = None
        self.include = [] if include is None else include
        self.pidfile = pidfile
        self.autoscale = None
        self.autoreload = autoreload
        if autoscale:
            max_c, _, min_c = autoscale.partition(",")
            self.autoscale = [int(max_c), min_c and int(min_c) or 0]
        self._isatty = isatty(sys.stdout)

        self.colored = app.log.colored(self.logfile)

        if isinstance(self.use_queues, basestring):
            self.use_queues = self.use_queues.split(",")
        if isinstance(self.include, basestring):
            self.include = self.include.split(",")

        try:
            self.loglevel = mlevel(self.loglevel)
        except KeyError:
            self.die("Unknown level %r. Please use one of %s." % (
                        self.loglevel,
                        "|".join(l for l in LOG_LEVELS.keys()
                                    if isinstance(l, basestring))))
Пример #6
0
 def run(self, hostname=None, pool_cls=None, loglevel=None,
         app=None, **kwargs):
     # Pools like eventlet/gevent needs to patch libs as early
     # as possible.
     pool_cls = (concurrency.get_implementation(pool_cls) or
                 self.app.conf.CELERYD_POOL)
     if self.app.IS_WINDOWS and kwargs.get('beat'):
         self.die('-B option does not work on Windows.  '
                  'Please run celerybeat as a separate service.')
     hostname = self.simple_format(hostname)
     if loglevel:
         try:
             loglevel = mlevel(loglevel)
         except KeyError:  # pragma: no cover
             self.die('Unknown level {0!r}. Please use one of {1}.'.format(
                 loglevel, '|'.join(l for l in LOG_LEVELS.keys()
                   if isinstance(l, basestring))))
     return self.app.Worker(
         hostname=hostname, pool_cls=pool_cls, loglevel=loglevel, **kwargs
     ).run()