Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Python实现zappa调度_Python_Twilio_Aws Lambda_Amazon Sns_Zappa - Fatal编程技术网

用Python实现zappa调度

用Python实现zappa调度,python,twilio,aws-lambda,amazon-sns,zappa,Python,Twilio,Aws Lambda,Amazon Sns,Zappa,我正在运行此代码发送短信与Twilio client.messages.create( to=form.phone.data, from_="+1xxxxxxxxxx", body="This is a text message" 我的应用程序使用Python的Zappa托管在AWS Lambda上。问题是,我需要能够安排在未来10分钟内发送此消息 Zappa提供了任务执行,但他们的文档不清楚应该如何执行这样的任务 感谢您的帮助。这不是Zapp

我正在运行此代码发送短信与Twilio

client.messages.create(
        to=form.phone.data, 
        from_="+1xxxxxxxxxx",
        body="This is a text message"
我的应用程序使用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)
       }],
       ...
    }
}
您的代码可以是这样的

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(...)
从日期时间导入日期时间
def send_msg():
form=get_form()
已用=datetime.now()-form.date\u已创建
如果10
我为zappa创建了一个db驱动的任务队列。早期,但我们正在生产中使用它

每X分钟,(正如@Oluwafemi Sule的回答中所建议的那样)一个Zappa事件ping一个检查任务的函数。任务可以延迟Y分钟,重复Z次等


我的解决方案很粗糙,因为它的时间分辨率很低,而且目前的水平很低。

很有趣。这是否需要服务器一直运行?Lambda在一段时间后死亡。Cloudwatch将每分钟调用该函数。处理方法是在调用函数时,对所用时间进行简单检查。如果经过的时间通过检查,则会发送消息。为什么不使用“表达式”:“速率(10分钟)”?那么您无法确定工作进程是否会在任务提交后的10分钟内运行任务。时间表每10分钟检查一次任务。您可能已在该期限内的某个时间发送了任务。如果一个人能够忍受相当大的延迟,就可以这样。Zappa现在支持异步任务执行: