我正在使用Django和Twilio api开发警报应用程序,以进行呼叫和消息发送。我使用类似以下功能,使用20个不同的电话号码发送近2000条呼叫和消息。
def call_number(phone_numbers, message_to_broadcast): # index twilio controls the phone number that the message is being sent from response = VoiceResponse() response.say('Hello. this is a test message ' + message_to_broadcast + 'Goodbye.', voice='alice' ) index_twilio= 0 try: for phones in phone_numbers: client.calls.create(to=phones, from_=numbers['twilio_numbers'][index_twilio], status_callback='https://mywebsite.com//ealert/voicedistribution/', twiml=response) index_twilio = (0 if index_twilio >= 19 else index_twilio+1) except (TwilioRestException): # A generic 400 or 500 level exception from the Twilio API continue
当我单击提交按钮时,我的应用程序一直保持加载状态。我想立即重定向到我的主页,并在后台运行此功能。
我的问题是:当服务器仍在后台拨打电话并发送消息时,如何恢复使用我的应用程序并立即重定向?一直在环顾四周,但我找不到足够的空间。
另一个问题是,是否有可能使速度更快,而不用这种方式运行我的两个功能:
def main(): call_number(phones, message) text_number(phones, message) main()
任何批评和/或帮助将不胜感激!
我正在使用Django和Twilio api开发警报应用程序,以进行呼叫和消息发送。我使用功能使用20个不同的电话号码发送近2000条呼叫和消息...
实现此目的的一种方法是实现队列。与其在函数调用中进行调用或消息传递,不如将它们添加到队列,重定向到主页,然后开始在后台处理队列。为此可以使用django-celery。您可以使用其他队列处理来代替芹菜。