perf: 优化 ops 任务,支持 i18n

- 内置任务名称支持了 i18n,数据库存英文,返回是翻译一下
- 任务执行中,添加 language 上下文
This commit is contained in:
ibuler
2022-01-13 14:18:32 +08:00
committed by Jiangjie.Bai
parent 43c4c78378
commit 145c7952c9
14 changed files with 127 additions and 88 deletions

View File

@@ -5,9 +5,10 @@ import time
from django.conf import settings
from celery import shared_task, subtask
from celery.exceptions import SoftTimeLimitExceeded
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _, gettext
from common.utils import get_logger, get_object_or_none, get_log_keep_day
from orgs.utils import tmp_to_root_org, tmp_to_org
@@ -141,10 +142,10 @@ def hello(name, callback=None):
import time
count = User.objects.count()
print("Hello {}".format(name))
print(gettext("Hello") + ': ' + name)
print("Count: ", count)
time.sleep(1)
return count
return gettext("Hello")
@shared_task
@@ -177,3 +178,4 @@ def add_m(x):
s.append(add.s(i))
res = chain(*tuple(s))()
return res