|
| 1 | +# coding: utf-8 |
1 | 2 | from __future__ import absolute_import |
2 | 3 |
|
3 | 4 | import os |
4 | | -import logging |
5 | 5 |
|
6 | 6 | from celery import Celery |
7 | 7 | from django.conf import settings |
8 | 8 |
|
9 | | -# set the default Django settings module for the 'celery' program. |
10 | | -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'configs.settings') |
11 | | -app = Celery('configs') |
| 9 | +# set the default Django settings module for the 'celery' program. |
| 10 | +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'configs.settings') |
| 11 | +app = Celery('configs') |
12 | 12 |
|
13 | | -# Using a string here means the worker will not have to |
14 | | -# pickle the object when using Windows. |
15 | | -app.config_from_object('django.conf:settings', namespace='CELERY') |
16 | | -app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) |
| 13 | +# Using a string here means the worker will not have to |
| 14 | +# pickle the object when using Windows. |
| 15 | +app.config_from_object('django.conf:settings', namespace='CELERY') |
| 16 | +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) |
17 | 17 |
|
18 | 18 | app.conf.update( |
19 | 19 | CELERY_TASK_SERIALIZER='json', |
20 | 20 | CELERY_ACCEPT_CONTENT=['json'], |
21 | 21 | CELERY_RESULT_SERIALIZER='json', |
| 22 | + CELERYD_CONCURRENCY=1, |
| 23 | + CELERY_WORKER_MAX_TASKS_PER_CHILD=200, # 完成一定数量后重启该worker |
| 24 | + CELERY_TIMEZONE='Asia/Shanghai' |
22 | 25 | ) |
23 | 26 |
|
24 | | -@app.task(bind=True) |
25 | | -def debug_task(self): |
26 | | - print('Request: {0!r}'.format(self.request)) |
| 27 | + |
| 28 | +@app.task(bind=True) |
| 29 | +def debug_task(self): |
| 30 | + print('Request: {0!r}'.format(self.request)) |
0 commit comments