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

Source Code for Module Products.ZenUtils.celeryintegration.loader

 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  from celery.loaders.base import BaseLoader 
12  from zenoss.protocols.amqpconfig import AMQPConfig 
13  from Products.ZenUtils.GlobalConfig import getGlobalConfiguration 
14   
15  from . import constants 
16   
17   
18 -class ZenossLoader(BaseLoader):
19 20 override_backends = { 21 'zodb': 'Products.ZenUtils.celeryintegration.ZODBBackend' 22 } 23
24 - def on_worker_process_init(self):
25 """ 26 Clear out connections and dbs 27 """ 28 self.app.backend.reset()
29
30 - def read_configuration(self):
31 """ 32 Build a Celery configuration dictionary using global.conf. 33 34 This configuration may be overwritten or augmented later by a daemon. 35 """ 36 globalCfg = getGlobalConfiguration() 37 amqpCfg = AMQPConfig() 38 amqpCfg.update(globalCfg) 39 40 config = { 41 42 ############# 43 # TRANSPORT # 44 ############# 45 46 constants.BROKER_HOST: amqpCfg.host, 47 constants.BROKER_PORT: amqpCfg.port, 48 constants.BROKER_USER: amqpCfg.user, 49 constants.BROKER_PASSWORD: amqpCfg.password, 50 constants.BROKER_VHOST: amqpCfg.vhost, 51 constants.BROKER_USE_SSL: amqpCfg.usessl, 52 constants.ACK_LATE: True, 53 ################ 54 # RESULT STORE # 55 ################ 56 57 constants.RESULT_BACKEND: 'zodb', 58 59 ########### 60 # WORKERS # 61 ########### 62 63 # Default to 1 job per worker process 64 constants.MAX_TASKS_PER_PROCESS: 1, 65 # 2 job workers 66 constants.NUM_WORKERS: 2, 67 68 ########### 69 # LOGGING # 70 ########### 71 72 # Handle logging ourselves 73 constants.USE_CELERY_LOGGING: False, 74 # Log file formats 75 constants.LOG_FORMAT: "%(asctime)s %(levelname)s %(name)s: %(message)s", 76 constants.TASK_LOG_FORMAT: "%(asctime)s %(levelname)s zen.Job: %(message)s", 77 # Level at which stdout should be logged 78 constants.STDOUT_LOG_LEVEL: 'INFO' 79 } 80 return config
81