from __future__ import absolute_import

import os

from celery import Celery
from trytond.config import config

config.update_etc()


broker_url = config.get('async', 'broker_url')
backend_url = config.get('async', 'backend_url')

app = Celery(
    'trytond_async',
    broker=broker_url or os.environ.get('TRYTOND_ASYNC__BROKER_URL'),
    backend=backend_url or os.environ.get('TRYTOND_ASYNC__BACKEND_URL'),
    include=['trytond_async.tasks']
)

app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600,
    CELERY_TASK_SERIALIZER='tryson',
    CELERY_RESULT_SERIALIZER='tryson',
    CELERY_ACCEPT_CONTENT=[
        'application/x-tryson',
        'application/x-python-serialize'
    ]
)

if __name__ == '__main__':
    app.start()

from __future__ import absolute_import

import os

from celery import Celery
from trytond.config import config

try:
    from raven import Client
    from raven.contrib.celery import register_signal
except ImportError:
    pass
else:
    if os.environ.get('SENTRY_DSN'):
        register_signal(Client(os.environ.get('SENTRY_DSN')))

config.update_etc()


broker_url = config.get('async', 'broker_url')
backend_url = config.get('async', 'backend_url')

app = Celery(
    'trytond_async',
    broker=broker_url or os.environ.get('TRYTOND_ASYNC__BROKER_URL'),
    backend=backend_url or os.environ.get('TRYTOND_ASYNC__BACKEND_URL'),
    include=['trytond_async.tasks']
)

app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600,
    CELERY_TASK_SERIALIZER='tryson',
    CELERY_RESULT_SERIALIZER='tryson',
    CELERY_ACCEPT_CONTENT=[
        'application/x-tryson',
        'application/x-python-serialize'
    ]
)

if __name__ == '__main__':
    app.start()

Use raven for logging if available
Use raven for logging if available

  from __future__ import absolute_import
  
  import os
  
  from celery import Celery
  from trytond.config import config
+ 
+ try:
+     from raven import Client
+     from raven.contrib.celery import register_signal
+ except ImportError:
+     pass
+ else:
+     if os.environ.get('SENTRY_DSN'):
+         register_signal(Client(os.environ.get('SENTRY_DSN')))
  
  config.update_etc()
  
  
  broker_url = config.get('async', 'broker_url')
  backend_url = config.get('async', 'backend_url')
  
  app = Celery(
      'trytond_async',
      broker=broker_url or os.environ.get('TRYTOND_ASYNC__BROKER_URL'),
      backend=backend_url or os.environ.get('TRYTOND_ASYNC__BACKEND_URL'),
      include=['trytond_async.tasks']
  )
  
  app.conf.update(
      CELERY_TASK_RESULT_EXPIRES=3600,
      CELERY_TASK_SERIALIZER='tryson',
      CELERY_RESULT_SERIALIZER='tryson',
      CELERY_ACCEPT_CONTENT=[
          'application/x-tryson',
          'application/x-python-serialize'
      ]
  )
  
  if __name__ == '__main__':
      app.start()
  
Use raven for logging if available
## Code Before:
from __future__ import absolute_import

import os

from celery import Celery
from trytond.config import config

config.update_etc()


broker_url = config.get('async', 'broker_url')
backend_url = config.get('async', 'backend_url')

app = Celery(
    'trytond_async',
    broker=broker_url or os.environ.get('TRYTOND_ASYNC__BROKER_URL'),
    backend=backend_url or os.environ.get('TRYTOND_ASYNC__BACKEND_URL'),
    include=['trytond_async.tasks']
)

app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600,
    CELERY_TASK_SERIALIZER='tryson',
    CELERY_RESULT_SERIALIZER='tryson',
    CELERY_ACCEPT_CONTENT=[
        'application/x-tryson',
        'application/x-python-serialize'
    ]
)

if __name__ == '__main__':
    app.start()

## Instruction:
Use raven for logging if available
## Code After:
from __future__ import absolute_import

import os

from celery import Celery
from trytond.config import config

try:
    from raven import Client
    from raven.contrib.celery import register_signal
except ImportError:
    pass
else:
    if os.environ.get('SENTRY_DSN'):
        register_signal(Client(os.environ.get('SENTRY_DSN')))

config.update_etc()


broker_url = config.get('async', 'broker_url')
backend_url = config.get('async', 'backend_url')

app = Celery(
    'trytond_async',
    broker=broker_url or os.environ.get('TRYTOND_ASYNC__BROKER_URL'),
    backend=backend_url or os.environ.get('TRYTOND_ASYNC__BACKEND_URL'),
    include=['trytond_async.tasks']
)

app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600,
    CELERY_TASK_SERIALIZER='tryson',
    CELERY_RESULT_SERIALIZER='tryson',
    CELERY_ACCEPT_CONTENT=[
        'application/x-tryson',
        'application/x-python-serialize'
    ]
)

if __name__ == '__main__':
    app.start()
