我运行这段代码是为了和Twilio一起发送短信..。
client.messages.create(
to=form.phone.data,
from_="+1xxxxxxxxxx",
body="This is a text message"
我的应用程序托管在AWS Lambda上,使用Python的Zappa。问题是,我需要能够安排这条消息在未来10分钟内发送。
Zappa提供了任务执行,但是他们的文档不清楚应该如何完成这样的事情。
谢谢你的帮助。
发布于 2017-05-26 12:26:29
这不是Zappa现在直接支持的东西。您将需要在可用的调度系统周围执行某种类型的攻击。
将事件安排为每分钟运行一次:
{
"production": {
...
"events": [{
"function": "your_module.send_msg", // The function to execute
"expression": "rate(1 minute)" // When to execute it (in cron or rate format)
}],
...
}
}
您的代码可以沿着这些路线进行。
from datetime import datetime
def send_msg():
form = get_form()
elapsed = datetime.now() - form.date_created
if 10 < abs(elapsed.total_seconds())/60) < 11: # this is naive
client.messages.create(...)
发布于 2017-08-16 12:07:15
我为zappa创建了一个db驱动的任务队列。https://github.com/andytwoods/zappa-call-later。早期,但我们在生产中使用它。
每隔X分钟(正如@Oluwafemi的答案中所建议的那样),Zappa事件就会调用一个检查任务的函数。任务可以延迟Y分钟,重复Z次等。
我的解决方案很粗糙,因为它的时间分辨率很低,而且目前的水平很低。
https://stackoverflow.com/questions/44208455
复制