【问题标题】:how we can add a new task in celery without stop celery instance in django celery?我们如何在 celery 中添加新任务而不停止 django celery 中的 celery 实例?
【发布时间】:2016-07-23 14:32:35
【问题描述】:
@shared_task
def forgot_email(subject,user_cipher,key_cipher,to):
   print "comes here in the mail"
   try:
      email_content = {'user_cipher':user_cipher,'key_cipher':  key_cipher}
      message = render_to_string('forgot_password.txt',email_content)
      send_mail(subject, message, settings.EMAIL,to, fail_silently=False) 
      except Exception,e:
      print "Exception",e
    except:
       print 'exp'

@shared_task
def multiplesendmail(subject,body,first_name,to):
    print "comes here in the mail"
    try:
        print 'subject',subject,'body',body,'first_name',first_name,'to',to
        # email_content = {'first_name':first_name,'user_cipher':user_cipher,'key_cipher':key_cipher}
        # message = render_to_string('email_verification.txt', email_content)
        send_mail(subject,body,settings.EMAIL,to,fail_silently=False) 
    except Exception,e:
        print "Exception",e

注意-我想在不停止 celery 的情况下添加新任务。我必须先用这个停止芹菜,然后

celery -A HealthBrio worker -l info

【问题讨论】:

    标签: django python-2.7 celery celerybeat djcelery


    【解决方案1】:

    这是您想要的链接。您可以使用 django 的管理界面设置 crontab。 启动任务有两种方式:

    通过调度程序,它将在每个时间段(例如 10 秒)或每个特定时间(如 crontab 执行)调用任务。 从代码,在需要的地方和需要的条件下。 通过调度程序启动任务 转到地址 http://{host}/admin/djcelery/periodictask/ 的管理页面,然后按“添加定期任务”。

    如下面的屏幕截图所示填写字段,然后按保存。

    每 10 秒启动一次周期性任务

    要指示启动时间而不是周期,与前面的情况一样,但填写 Crontab(必须为空白间隔):

    更多详情http://www.lexev.org/en/2014/django-celery-setup/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 2011-07-18
      • 2011-07-17
      • 2020-12-25
      • 2012-04-28
      相关资源
      最近更新 更多