私は最近、ソフトウェア開発に取り組んでおり、セロリを思い通りに曲げることに成功しています。
私はそれを使用して電子メールを送信し、(すべてのプロセスを再起動した後などに) ほぼ同じコードを使用して、Twilio 経由で SMS を送信しようとしました。
ただし、次の問題が発生し続けます。
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'
私のコードは次のとおりです。
@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)
私のviews.pyから呼び出されたときの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', 'sender@example.com', 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 セロリ装飾関数は、登録されたタスクとして表示されます:
(env)RP:secTrial Rob$ celery inspect registered
-> celery@RP.local: OK
* app.send_email
* app.send_security_email
* app.send_sms
そして設定のために私は単純にguest:rabbitmqを使用しています
CELERY_BROKER_URL = 'amqp://guest@localhost//'
CELERY_RESULT_BACKEND = 'amqp://guest@localhost//'