zappa scheduling with Python

懵懂的女人 提交于 2019-12-01 23:59:26

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

I made a db driven task queue for zappa. https://github.com/andytwoods/zappa-call-later . Early days, but we are using it in production.

Every X minutes, (as suggested in @Oluwafemi Sule's answer) a Zappa event pings a function that checks for tasks. Tasks can be delayed Y minutes, repeated Z times etc.

My solution is crude in that it has low time resolution, and is quite low level currently.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!