python - cron 事件的 chalice @app.schedule 语法是什么?
问题描述
我正在尝试遵循https://chalice.readthedocs.io/en/latest/topics/events.html中的文档
我试过这个
@app.schedule('0 0 * * ? *')
def dataRefresh(event):
print(event.to_dict())
并得到这个错误:
botocore.exceptions.ClientError:调用 PutRule 操作时发生错误 (ValidationException):参数 ScheduleExpression 无效。
所以尝试了这个:
@app.schedule(Cron('0 0 * * ? *'))
def dataRefresh(event):
print(event.to_dict())
并得到了另一个错误:
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'}
这是包含更多信息的文档。Cron
或者使用这种语法,它不需要额外的导入:
@app.schedule('cron(0 0 * * ? *)')
def dataRefresh(event):
print(event.to_dict())
推荐阅读
- c - 如何在delphi中创建文件将其传递给C DLL并在回调中使用该文件?
- mongoose - 如何在查找结果中使用 mongoose virtuals
- c++ - 如何翻转像素数据的Y轴
- php - 如何使用干预从 Laravel 中的表单输入在图像上写入文本
- javascript - 如何修复:在迁移中,原始查询在 varchar 中对广告反斜杠转义进行续集,这会在将该值插入数据库时导致错误
- azure - Visual Studio 2017 - 部署到 Azure Function v2 (.NetCore v2.1) 错误:所需进程(“Web 管理服务”)已启动
- android - Fragment中的Edittext在编辑时跳到顶部并与工具栏重叠
- python - 如何访问 tkinter 中不同类的变量以在不同的函数中使用?
- visual-studio-code - 如何在 Visual Studio 代码中获取当前打开文件的文件夹路径名称
- android - 如何实现shadertoy itime?