Advertisement
Guest User

Untitled

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