使用Python进行zappa调度 [英] zappa scheduling with Python

查看:297
本文介绍了使用Python进行zappa调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running this code to send a sms message with Twilio...

client.messages.create(
        to=form.phone.data, 
        from_="+1xxxxxxxxxx",
        body="This is a text message"

我的应用程序使用Python的Zappa托管在AWS Lambda上.问题是我需要能够安排此消息在将来的10分钟内发送.

My application is hosted on AWS Lambda using Python's Zappa. The problem is that I need to be able to schedule this message to be sent 10 minutes in the future.

Zappa提供了任务执行功能,但他们的文档尚不清楚应如何执行.

Zappa offers task execution but their documentation is unclear for how something like this should be done.

感谢您的帮助.

推荐答案

这不是Zappa目前直接支持的功能.您需要围绕可用的调度系统进行某种形式的修改.

This isn't something Zappa directly supports at this time. You'll need to perform a hack of some sort around the available scheduling system.

安排每分钟运行一次事件:

Schedule an event to run every minute:

{
    "production": {
       ...
       "events": [{
           "function": "your_module.send_msg", // The function to execute
           "expression": "rate(1 minute)" // When to execute it (in cron or rate format)
       }],
       ...
    }
}

您的代码可以遵循这些原则.

Your code can be along these lines.

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(...)

这篇关于使用Python进行zappa调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆