How to check if celery task is running or not from django templates

故事扮演 提交于 2021-01-29 10:18:04

问题


I need some help for implementing django celery properly

Q1: Set custom id for celery task

@shared_task
def lazy_post_link_1_task(post_url, current_user, no_of_lazy_bot, no_of_comment_for_lazy_bot,
                          lazy_bot_time_interval):
    instagram_bot = InstagramBot()
    lazy_bots = InstagramModel.objects.filter(Q(bot_type='lazy_bot') & Q(running_status='idle'))[
                :int(no_of_lazy_bot)]
    for bot in lazy_bots:
        lazy_bot_filter_comments = Comments.objects.all().exclude(botscomment__bot_id=bot.id)[
                                   :int(no_of_comment_for_lazy_bot)]
        instagram_bot.comment_on_post(post_url, current_user, bot.id, bot.email, bot.password, lazy_bot_time_interval,
                                      lazy_bot_filter_comments)

Q2: How to check if this task is running or not from django templates and in from django view? for example:

if lazy_post_link_1_task.status == running:
  # do some stuff
else:
  # do some stuff

Q3: How to kill the task from django templates

来源:https://stackoverflow.com/questions/59896218/how-to-check-if-celery-task-is-running-or-not-from-django-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!