fre*_*313 3 python twilio amazon-sns zappa aws-lambda
我正在运行此代码以使用 Twilio 发送短信...
client.messages.create(
to=form.phone.data,
from_="+1xxxxxxxxxx",
body="This is a text message"
Run Code Online (Sandbox Code Playgroud)
我的应用程序使用 Python 的 Zappa 托管在 AWS Lambda 上。问题是我需要能够安排这条消息在未来 10 分钟内发送。
Zappa 提供任务执行,但他们的文档不清楚应该如何完成这样的事情。
谢谢您的帮助。
这不是 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)
}],
...
}
}
Run Code Online (Sandbox Code Playgroud)
您的代码可以遵循这些原则。
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(...)
Run Code Online (Sandbox Code Playgroud)