跳到内容

调度

schedule schedule

工作流可以通过调度重复运行。这适用于工作流针对动态扩展的输入(例如 API 服务或文件目录)运行的情况。

schedule 方法接受一个 cron 表达式、静态元素列表(这些元素会动态扩展,例如 API 服务、目录列表)以及一个可选的最大迭代次数。

以下是几个 cron 表达式示例。

# ┌─────────────── minute (0 - 59)
# | ┌───────────── hour (0 - 23)
# | | ┌─────────── day of the month (1 - 31)
# | | | ┌───────── month (1 - 12)
# | | | | ┌─────── day of the week (0 - 6)
# | | | | | ┌───── second (0 - 59)
# | | | | | |
  * * * * * *      # Run every second
0/5 * * * *        # Run every 5 minutes
  0 0 1 * *        # Run monthly on 1st
  0 0 1 1 *        # Run on Jan 1 at 12am
  0 0 * * mon,wed  # Run Monday and Wednesday

Python

使用 Python 调度简单工作流。

workflow = Workflow(tasks)
workflow.schedule("0/5 * * * *", elements)

请参阅下方链接获取更详细的示例。

笔记本 描述
工作流调度 使用 cron 表达式调度工作流 Open In Colab

配置

使用配置调度简单工作流。

workflow:
  index:
    schedule:
      cron: 0/5 * * * *
      elements: [...]
    tasks: [...]
# Create and run the workflow
from txtai import Application

# Create and run the workflow
app = Application("workflow.yml")

# Wait for scheduled workflows
app.wait()

请参阅下方链接获取更多关于 cron 表达式的信息。