Package Products :: Package ZenUtils :: Package celeryintegration |
[hide private]
[frames] | no frames]

# Source Code for Package Products.ZenUtils.celeryintegration

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2012, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  __doc__ = """
    12  Import celery classes from this package exclusively, as it ensures the
    13  environment has been set up first.
    14  """
    15  import os
    16
    17  LOADERFQDN = "Products.ZenUtils.celeryintegration.ZenossLoader"
    18
    19  os.environ.setdefault('CELERY_LOADER', LOADERFQDN)
    20
    21  from celery import states
    22
    23  from .loader import ZenossLoader
    24  from .backend import ZODBBackend
    25  from .app import ZenossCelery
    26
    27  from celery.contrib.abortable import AbortableTask as Task, ABORTED
    28
    29  for _attr in ('PROPAGATE_STATES', 'EXCEPTION_STATES', 'READY_STATES', 'ALL_STATES'):
    30      setattr(states, _attr, frozenset(set((ABORTED,)) | getattr(states, _attr)))
    31  del _attr
    32
    33  from celery.app.state import current_app
    34
    35
    36 -def reconfigure_celery(config, updateonly=True):
    37      """
    38      Reconfigure Celery with new config.
    39
    40      @param config: The new configuration to be applied.
    41      @type config: dict
    42      @param updateonly: Whether to update the existing config (versus replace)
    43      @type updateonly: bool
    44      """
    45      newconfig = {}
    46      if updateonly:
    47          newconfig.update(current_app.conf)
    48      newconfig.update(config)
    49      current_app.config_from_object(newconfig)
    50