安排 Data Kiosk 查询
了解如何安排数据亭查询。
Use this guide to learn how to automatically make regular calls to createQuery
while avoiding redundant data requests.
注意
A full code sample for this scheduling mechanism is published in our Samples Repo on GitHub.
数据亭概述
使用数据亭涉及以下步骤:
- 订阅通知: 将 SQS 队列订阅到
DATA_KIOSK_QUERY_PROCESSING_FINISHED
通知,它会在数据处理完成时通知您。 - Create the query: Submit a GraphQL query using the
createQuery
operation. - Retrieve the document: Use
dataDocumentId
orerrorDocumentId
to retrieve document details with thegetDocument
operation. These attributes are in the notification payload. If you receiveerrorDocumentId
, you can find the reason for the failure in the document. - Store the data: Retrieve and store the JSONL file from the
documentUrl
for further processing and access.
注意
有关 Data Kiosk 工作流程的更多信息,请参阅:
教程:为 Data Kiosk 构建调度机制
了解如何自动和定期向数据亭进行查询,同时避免冗余呼叫。
第 1 步。定义计划参数
确定开始日期和要进行查询的速率。
注意
如果查询的开始日期已过去,并且您希望调度程序回填,请尽可能频繁地创建查询,直到当天查询为止。这样可以确保您的数据保持最新状态。例如,如果开始日期是一个月前,并且您需要每天的信息,请调整解决方案,以便调度程序快速运行过去一个月中的每一天的查询,直到到达当天为止。
如果您不需要回填,请将开始日期设置为现在或将来的日期,以避免调度程序创建过去的查询。
常见频率包括每天、每周或每月。速率的选择取决于您的数据更新频率。例如,如果您的数据每天更新,则每日频率是合适的。不要过于频繁地查询。如果数据集每天更新,则每小时的查询将是多余的。
第 2 步。调整查询参数
创建一个函数,根据所需的速率调整查询的开始和结束日期,以便每个查询都检索新数据。例如,如果计划速率为每天,则该函数应将每个新查询的开始和结束日期调整一天。
请注意!
不同的数据集具有不同的属性键名称和不同的数据重载周期。了解每个数据集的开始日期和结束日期的属性键。当您更新或移动开始和结束日期属性时,键名可能会因数据集而异。
第 3 步。创建查询
To automatically submit queries, use an event scheduler such as AWS EventBridge. With EventBridge, you can set up recurring tasks using cron expressions or rate expressions (for example, every five minutes, hourly, daily). Configure EventBridge to automatically adjust query dates and make the calls to createQuery
at defined intervals to continuously and efficiently retrieve data.
第 4 步。保存日程信息
将开始日期、费率和相关查询等日程安排信息存储在数据库中。确保您可以根据需要取消或删除计划,并保留查询日志以供审计和报告之用。
最佳实践和注意事项
避免错误并处理冗余。需要考虑的一些事项包括:
-
避免冗余: 验证查询是否请求唯一数据。确保与先前存储的数据时间戳没有重叠,并且不要为同一个查询创建多个计划。如果先前的查询仍在运行,则查询创建失败。
-
记录错误: 不要允许失败的查询停止整个调度机制。实施全面的日志记录以捕获查询提交和数据检索期间的错误。处理 Data Kiosk 返回的错误文档并修复其中包含的错误。
-
重试: 如果查询受到并发查询限制的限制,则应采用使用指数退避的重试机制。
-
监控和警报: 实时监控并设置错误警报,以防查询失败、超出速率限制或处理时间延长。快速识别和响应问题。
For details about different errors and how to fix them, refer to Handling processing errors.
Updated 23 days ago