本文介绍了使用 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 调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 12:50