zappa scheduling with Python

后端 未结 2 1838
轻奢々
轻奢々 2021-01-22 00:09

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

client.messages.create(
        to=form.phone.data, 
        from_=\"+1xxxxxxxxxx\",
        body=\"T         


        
2条回答
  •  萌比男神i
    2021-01-22 00:49

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

提交回复
热议问题