feat: 更新celery.py 添加重试机制
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
|
import functools
|
||||||
import os
|
import os
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from celery import platforms
|
from celery import platforms
|
||||||
|
|
||||||
# 租户模式
|
# 租户模式
|
||||||
if "django_tenants" in settings.INSTALLED_APPS:
|
if "django_tenants" in settings.INSTALLED_APPS:
|
||||||
from tenant_schemas_celery.app import CeleryApp as TenantAwareCeleryApp
|
from tenant_schemas_celery.app import CeleryApp as TenantAwareCeleryApp
|
||||||
@@ -16,3 +18,23 @@ else:
|
|||||||
app.config_from_object('django.conf:settings')
|
app.config_from_object('django.conf:settings')
|
||||||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
||||||
platforms.C_FORCE_ROOT = True
|
platforms.C_FORCE_ROOT = True
|
||||||
|
|
||||||
|
|
||||||
|
def retry_base_task_error():
|
||||||
|
"""
|
||||||
|
celery 失败重试装饰器
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
def wraps(func):
|
||||||
|
@app.task(bind=True, retry_delay=180, max_retries=3)
|
||||||
|
@functools.wraps(func)
|
||||||
|
def wrapper(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
except Exception as exc:
|
||||||
|
raise self.retry(exc=exc)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
return wraps
|
||||||
|
|||||||
Reference in New Issue
Block a user