2014-10-16 91 views
8

最近我一直在通過軟件開發攪拌,並且順利地將芹菜彎曲成我的意志。芹菜難度:功能對象沒有屬性'延遲'

我已經成功地使用它發送電子郵件,並試圖使用幾乎完全相同的代碼(在重新啓動所有進程等後)通過Twilio發送短信。

不過,我不斷收到了以下問題:

File "/Users/Rob/Dropbox/Python/secTrial/views.py", line 115, in send_sms 
send_sms.delay(recipients, form.text.data) 
AttributeError: 'function' object has no attribute 'delay' 

我的代碼如下:從我views.py調用時

@celery.task 
def send_email(subject, sender, recipients, text_body): 
    msg = Message(subject, sender=sender) 
    for email in recipients: 
     msg.add_recipient(email) 
    msg.body = text_body 
    mail.send(msg) 

@celery.task 
def send_sms(recipients, text_body): 
    for number in recipients: 
     print number 
     num = '+61' + str(number) 
     print num 
     msg = text_body + 'this message to' + num 
     client.messages.create(to=num, from_="+14804054823", body=msg) 

send_email.delay完美的作品,但是send_sms.delay失敗每次都有上述錯誤。

任何幫助解決這個問題表示讚賞。

- 按照要求:

@app.route('/send_mail', methods=['GET', 'POST']) 
@roles_accepted('Admin') 
def send_mail(): 
    form = SendMailForm(request.form) 
    if request.method == 'POST': 
     if form.validate_on_submit(): 
      emails = db.session.query(User.email).all() 
      list_emails = list(zip(*emails)[0]) 
      send_email.delay('Subject', '[email protected]', list_emails, form.text.data) 
    return render_template('send_generic.html', form=form) 

@app.route('/send_sms', methods=['GET', 'POST']) 
@roles_accepted('Admin') 
def send_sms(): 
    form = SendMailForm(request.form) 
    if request.method == 'POST': 
     if form.validate_on_submit(): 
      recipients = db.session.query(User.mobile).all() 
      list_recipients = filter(None, list(zip(*recipients)[0])) 
      send_sms.delay(list_recipients, form.text.data) 
    return render_template('send_generic.html', form=form, send_sms=send_sms) 

我send_sms芹菜裝飾功能被顯示爲一個註冊任務:

和配置我只是使用guest:RabbitMQ的

CELERY_BROKER_URL = 'amqp://[email protected]//' 
CELERY_RESULT_BACKEND = 'amqp://[email protected]//' 
+0

你可以發佈你的芹菜配置和意見? – ChillarAnand 2014-10-16 17:30:38

回答

12

視圖名稱send_sms與芹菜任務名稱衝突。名稱send_sms在包含視圖的模塊中使用時引用視圖,而不是任務。

使用不同的名稱來避免覆蓋。

+0

我不敢相信我沒有看到那裏有問題。 非常感謝,治癒了。 – rob123 2014-10-17 00:36:25

相關問題