Ale*_*x R 2 python amazon-web-services chalice
我正在尝试遵循https://chalice.readthedocs.io/en/latest/topics/events.html 中的文档
我试过这个
@app.schedule('0 0 * * ? *')
def dataRefresh(event):
print(event.to_dict())
Run Code Online (Sandbox Code Playgroud)
并收到此错误:
botocore.exceptions.ClientError:调用 PutRule 操作时发生错误 (ValidationException):参数 ScheduleExpression 无效。
所以试过这个:
@app.schedule(Cron('0 0 * * ? *'))
def dataRefresh(event):
print(event.to_dict())
Run Code Online (Sandbox Code Playgroud)
并得到了另一个错误:
NameError:未定义名称“Cron”
什么都不起作用……正确的语法是什么?
如果要使用Cron对象,必须从 chalice 包中导入它,然后每个值都是Cron对象的位置参数:
from chalice import Chalice, Cron
app = Chalice(app_name='sched')
@app.schedule(Cron(0, 0, '*', '*', '?', '*'))
def my_schedule():
return {'hello': 'world'}
Run Code Online (Sandbox Code Playgroud)
下面是文档的Cron拥有更多的信息。
或者,也可以使用此语法,无需额外导入即可工作:
@app.schedule('cron(0 0 * * ? *)')
def dataRefresh(event):
print(event.to_dict())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
638 次 |
| 最近记录: |