Esempio n. 1
0
 def _dispatch_event(self, event):
     self.event_count += 1
     event = kwdict(event)
     group, _, type = partition(event.pop("type"), "-")
     self.group_handlers[group](type, event)
     if self.event_callback:
         self.event_callback(self, event)
Esempio n. 2
0
 def _dispatch_event(self, event):
     self.event_count += 1
     event = kwdict(event)
     group, _, type = partition(event.pop("type"), "-")
     self.group_handlers[group](type, event)
     if self.event_callback:
         self.event_callback(self, event)
Esempio n. 3
0
 def event(self, event):
     """Process event."""
     self.event_count += 1
     event = kwdict(event)
     group, _, type = partition(event.pop("type"), "-")
     self.group_handlers[group](type, event)
     if self.event_callback:
         self.event_callback(self, event)
 def event(self, event):
     """Process event."""
     self.event_count += 1
     event = kwdict(event)
     group, _, type = partition(event.pop("type"), "-")
     self.group_handlers[group](type, event)
     if self.event_callback:
         self.event_callback(self, event)
Esempio n. 5
0
 def completenames(self, text, *ignored):
     """Return all commands starting with ``text``, for tab-completion."""
     names = self.get_names()
     first = [cmd for cmd in names
                     if cmd.startswith(text.replace("_", "."))]
     if first:
         return first
     return [cmd for cmd in names
                 if partition(cmd, ".")[2].startswith(text)]
Esempio n. 6
0
 def __init__(self, expires=conf.TASK_RESULT_EXPIRES,
         backend=conf.CACHE_BACKEND, options={}, **kwargs):
     super(CacheBackend, self).__init__(self, **kwargs)
     if isinstance(expires, timedelta):
         expires = timeutils.timedelta_seconds(expires)
     self.expires = expires
     self.options = dict(conf.CACHE_BACKEND_OPTIONS, **options)
     self.backend, _, servers = partition(backend, "://")
     self.servers = servers.split(";")
Esempio n. 7
0
def rate(rate):
    """Parses rate strings, such as ``"100/m"`` or ``"2/h"``
    and converts them to seconds."""
    if rate:
        if isinstance(rate, basestring):
            ops, _, modifier = partition(rate, "/")
            return RATE_MODIFIER_MAP[modifier or "s"](int(ops)) or 0
        return rate or 0
    return 0
Esempio n. 8
0
def rate(rate):
    """Parses rate strings, such as ``"100/m"`` or ``"2/h"``
    and converts them to seconds."""
    if rate:
        if isinstance(rate, basestring):
            ops, _, modifier = partition(rate, "/")
            return RATE_MODIFIER_MAP[modifier or "s"](int(ops)) or 0
        return rate or 0
    return 0
Esempio n. 9
0
    def __init__(self, concurrency=None, loglevel=None, logfile=None,
            hostname=None, discard=False, run_clockservice=False,
            schedule=None, task_time_limit=None, task_soft_time_limit=None,
            max_tasks_per_child=None, queues=None, events=False, db=None,
            include=None, app=None, pidfile=None,
            redirect_stdouts=None, redirect_stdouts_level=None,
            autoscale=None, scheduler_cls=None, **kwargs):
        self.app = app = app_or_default(app)
        self.concurrency = (concurrency or
                            app.conf.CELERYD_CONCURRENCY or
                            multiprocessing.cpu_count())
        self.loglevel = loglevel or app.conf.CELERYD_LOG_LEVEL
        self.logfile = logfile or app.conf.CELERYD_LOG_FILE
        self.hostname = hostname or socket.gethostname()
        self.discard = discard
        self.run_clockservice = run_clockservice
        self.schedule = schedule or app.conf.CELERYBEAT_SCHEDULE_FILENAME
        self.scheduler_cls = scheduler_cls or app.conf.CELERYBEAT_SCHEDULER
        self.events = events
        self.task_time_limit = (task_time_limit or
                                app.conf.CELERYD_TASK_TIME_LIMIT)
        self.task_soft_time_limit = (task_soft_time_limit or
                                     app.conf.CELERYD_TASK_SOFT_TIME_LIMIT)
        self.max_tasks_per_child = (max_tasks_per_child or
                                    app.conf.CELERYD_MAX_TASKS_PER_CHILD)
        self.redirect_stdouts = (redirect_stdouts or
                                 app.conf.CELERY_REDIRECT_STDOUTS)
        self.redirect_stdouts_level = (redirect_stdouts_level or
                                       app.conf.CELERY_REDIRECT_STDOUTS_LEVEL)
        self.db = db
        self.use_queues = queues or []
        self.queues = None
        self.include = include or []
        self.pidfile = pidfile
        self.autoscale = None
        if autoscale:
            max_c, _, min_c = partition(autoscale, ",")
            self.autoscale = [int(max_c), min_c and int(min_c) or 0]
        self._isatty = sys.stdout.isatty()
        self.colored = term.colored(enabled=app.conf.CELERYD_LOG_COLOR)

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

        if not isinstance(self.loglevel, int):
            try:
                self.loglevel = LOG_LEVELS[self.loglevel.upper()]
            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))))
Esempio n. 10
0
def parse_ratelimit_string(rate_limit):
    """Parse rate limit configurations such as ``"100/m"`` or ``"2/h"``
        and convert them into seconds.

    Returns ``0`` for no rate limit.

    """

    if rate_limit:
        if isinstance(rate_limit, basestring):
            ops, _, modifier = partition(rate_limit, "/")
            return RATE_MODIFIER_MAP[modifier or "s"](int(ops)) or 0
        return rate_limit or 0
    return 0
Esempio n. 11
0
 def __init__(self, expires=conf.TASK_RESULT_EXPIRES,
         backend=conf.CACHE_BACKEND, options={}, **kwargs):
     super(CacheBackend, self).__init__(self, **kwargs)
     if isinstance(expires, timedelta):
         expires = timeutils.timedelta_seconds(expires)
     self.expires = int(expires)
     self.options = dict(conf.CACHE_BACKEND_OPTIONS, **options)
     self.backend, _, servers = partition(backend, "://")
     self.servers = servers.split(";")
     try:
         self.Client = backends[self.backend]
     except KeyError:
         raise ImproperlyConfigured(
                 "Unknown cache backend: %s. Please use one of the "
                 "following backends: %s" % (self.backend,
                                             ", ".join(backends.keys())))
Esempio n. 12
0
def parse_ratelimit_string(rate_limit):
    """Parse rate limit configurations such as ``"100/m"`` or ``"2/h"``
        and convert them into seconds.

    Returns ``0`` for no rate limit.

    """

    if rate_limit:
        if isinstance(rate_limit, basestring):
            base = BASE_IDENTIFIERS.get(rate_limit[:2], 10)
            try:
                return int(rate_limit, base)
            except ValueError:
                ops, _, modifier = partition(rate_limit, "/")
                return RATE_MODIFIER_MAP[modifier](int(ops, base)) or 0
        return rate_limit or 0
    return 0
Esempio n. 13
0
 def __init__(self,
              expires=conf.TASK_RESULT_EXPIRES,
              backend=conf.CACHE_BACKEND,
              options={},
              **kwargs):
     super(CacheBackend, self).__init__(self, **kwargs)
     if isinstance(expires, timedelta):
         expires = timeutils.timedelta_seconds(expires)
     self.expires = int(expires)
     self.options = dict(conf.CACHE_BACKEND_OPTIONS, **options)
     self.backend, _, servers = partition(backend, "://")
     self.servers = servers.split(";")
     try:
         self.Client = backends[self.backend]
     except KeyError:
         raise ImproperlyConfigured(
             "Unknown cache backend: %s. Please use one of the "
             "following backends: %s" %
             (self.backend, ", ".join(backends.keys())))
Esempio n. 14
0
 def test_partition_unicode(self):
     s = u'hi mom'
     self.assertEqual(utils.partition(s, ' '), (u'hi', u' ', u'mom'))
Esempio n. 15
0
 def test_partition_unicode(self):
     s = u'hi mom'
     self.assertEqual(utils.partition(s, ' '), (u'hi', u' ', u'mom'))