问题
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