Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1.  
  2. import os
  3. import sys
  4.  
  5. from kombu import Exchange, Queue
  6. from datetime import timedelta
  7. from config import cfg
  8.  
  9. import log
  10.  
  11. log.initLog(cfg.log)
  12.  
  13. sys.path.append(os.path.dirname(os.path.basename(__file__)))
  14.  
  15.  
  16. _redis = cfg.redis
  17. _email = cfg.email
  18.  
  19. REDIS_SERVER = "redis://:%s@%s:%d/%d" %(_redis['password'],_redis['host'],\
  20. _redis['port'],_redis['db'])
  21.  
  22. BROKER_URL = REDIS_SERVER
  23.  
  24.  
  25. BROKER_POOL_LIMIT = 200
  26.  
  27. BROKER_CONNECTION_TIMEOUT = 5
  28. BROKER_CONNECTION_RETRY = True
  29. BROKER_CONNECTION_MAX_RETRIES = 100
  30.  
  31. BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600*12} # 12 hour
  32.  
  33. # BROKER_HEARTBEAT
  34. # BROKER_HEARTBEAT_CHECKRATE
  35.  
  36.  
  37. # Only AMQP broker support using ssl
  38. BROKER_USE_SSL = False
  39.  
  40.  
  41. CELERY_RESULT_BACKEND =REDIS_SERVER
  42.  
  43. CELERY_TIMEZONE = "Asia/Shanghai"
  44.  
  45. CELERY_TASK_RESULT_EXPIRES = 3600*24 # 1 day
  46.  
  47. CELERYD_CONCURRENCY = 6
  48.  
  49. CELERY_TASK_SERIALIZER = 'json'
  50. CELERY_RESULT_SERIALIZER = 'json'
  51.  
  52. CELERY_CACHE_BACKEND = "memory"
  53.  
  54. CELERY_TASK_PUBLISH_RETRY = True
  55. CELERY_TASK_PUBLISH_RETRY_POLICY = {
  56. 'max_retries': 3,
  57. 'interval_start': 0,
  58. 'interval_step': 30,
  59. 'interval_max': 60,
  60. }
  61.  
  62.  
  63. CELERYD_POOL = "processes"
  64.  
  65.  
  66. CELERY_IMPORTS = (
  67. 'tasks',
  68. 'urlscan.tasks',
  69. 'codescan.tasks',
  70. 'webscan.tasks'
  71. )
  72.  
  73.  
  74. #################################################
  75. #: Queue and Route related configuration
  76. #################################################
  77.  
  78. CELERY_DEFAULT_EXCHANGE_TYPE = 'direct'
  79.  
  80. CELERY_QUEUES = (
  81. Queue('errorhandler',Exchange('errorhandler'),routing_key='errorhandler'),
  82. Queue('urlscan.log',Exchange('urlscan.log'),routing_key='urlscan.log'),
  83. Queue('urlscan.spider',Exchange('urlscan.spider'),routing_key='urlscan.spider'),
  84. Queue('webscan',Exchange('webscan'),routing_key='webscan'),
  85. Queue('codescan',Exchange('codescan'),routing_key='codescan'),
  86.  
  87. )
  88.  
  89.  
  90.  
  91. CELERY_ROUTES = ({
  92. 'webscan.errorhandler': {
  93. 'queue':'errorhandler',
  94. 'routing_key':'errorhandler'
  95. }},
  96.  
  97. {
  98. 'webscan.urlscan.spider': {
  99. 'queue': 'urlscan.spider',
  100. 'routing_key': 'urlscan.spider'
  101. }},
  102.  
  103. {
  104. 'webscan.urlscan.logextract': {
  105. 'queue': 'urlscan.log',
  106. 'routing_key': 'urlscan.log'
  107. }},
  108.  
  109. {
  110. 'webscan.codescan': {
  111. 'queue': 'codescan',
  112. 'routing_key': 'codescan'
  113. }},
  114.  
  115. {
  116. 'webscan.webscan': {
  117. 'queue': 'webscan',
  118. 'routing_key': 'webscan'
  119. }},
  120. )
  121.  
  122.  
  123.  
  124. #################################################
  125. #: Events configuration, Event can be used for monitor by flower
  126. #################################################
  127. CELERY_SEND_EVENTS = True
  128. CELERY_SEND_TASK_SENT_EVENT = True
  129.  
  130.  
  131.  
  132.  
  133. #################################################
  134. #: Log configuration
  135. #################################################
  136. CELERYD_HIJACK_ROOT_LOGGER = True
  137. CELERYD_LOG_COLOR = True
  138. CELERYD_LOG_FORMAT = "[%(asctime)s <%(processName)s>] %(levelname)s: %(message)s"
  139. CELERYD_TASK_LOG_FORMAT = "[%(asctime)s <%(task_name)s %(task_id)s>] %(levelname)s: %(message)s"
  140. CELERY_REDIRECT_STDOUTS = True
  141.  
  142.  
  143.  
  144.  
  145.  
  146. #################################################
  147. #: E-mail configuration, Send mail to admin when task failed.
  148. #################################################
  149. CELERY_SEND_TASK_ERROR_EMAILS = True
  150.  
  151. ADMINS = (
  152. ("kenshin", "kenshin.acs@gmail.com"),
  153. )
  154.  
  155. SERVER_EMAIL = _email['SERVER_EMAIL']
  156.  
  157. EMAIL_HOST = _email['EMAIL_HOST']
  158. EMAIL_PORT = _email['EMAIL_PORT']
  159. EMAIL_HOST_USER = _email['EMAIL_HOST_USER']
  160. EMAIL_HOST_PASSWORD = _email['EMAIL_HOST_PASSWORD']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement