Skip to content

Commit

Permalink
不再以来从django-db中获取结果
Browse files Browse the repository at this point in the history
  • Loading branch information
woshiyanghai committed Sep 19, 2024
1 parent 1bb9606 commit edbbe57
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion archery/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
Redis:没有相应的机制保证消息的消费,当消费者消费失败的时候,消息体丢失,需要手动处理
RabbitMQ:具有消息消费确认,即使消费者消费失败,也会自动使消息体返回原队列,同时可全程持久化,保证消息体被正确消费
'''
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/1'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/1' #必须要存储任务结果,代码中有一些需要判断任务状态
#CELERY_RESULT_BACKEND = 'django-db'
CELERY_BROKER_URL = 'redis://127.0.0.1:6379/2'
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
Expand Down
8 changes: 0 additions & 8 deletions sql/binlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,6 @@ def my2sql(request):
if save_sql:
args.pop("password")
args.pop("output-toScreen")
async_task(
my2sql_file,
args=args,
user=request.user,
hook=notify_for_my2sql,
timeout=-1,
task_name=f"my2sql-{time.time()}",
)
save_file_time = time.time()
my2sql_file.apply_async(
args=[
Expand Down
9 changes: 4 additions & 5 deletions sql/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
ArchiveConfigSerializer,
InstanceSerializer,
)
from django_celery_results.models import TaskResult
from celery.result import AsyncResult
from celery import shared_task
import json

Expand Down Expand Up @@ -547,15 +547,14 @@ def notify_for_my2sql(result,task_id):
:param task:
:return:
"""
task_result = TaskResult.objects.filter(task_id=task_id).first()
task_result = AsyncResult(task_id)
if task_result.status == 'SUCCESS':
data_list = json.loads(task_result.result)
result = My2SqlResult(
success=True, submitter=data_list[0], file_path=data_list[1]
success=True, submitter=result[0], file_path=result[1]
)
else:
result = My2SqlResult(
success=False, submitter=task_result.result[0], error=result
success=False, submitter=result[0], error=result
)
# 发送
sys_config = SysConfig()
Expand Down

0 comments on commit edbbe57

Please sign in to comment.