Schedule

schedule schedule

Workflows can run on a repeating basis with schedules. This is suitable in cases where a workflow is run against a dynamically expanding input, like an API service or directory of files.

The schedule method takes a cron expression, list of static elements (which dynamically expand i.e. API service, directory listing) and an optional maximum number of iterations.

Below are a couple example cron expressions.

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

Python

Simple workflow scheduled with Python.

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

See the link below for a more detailed example.

NotebookDescription
Workflow SchedulingSchedule workflows with cron expressionsOpen In Colab

Configuration

Simple workflow scheduled with configuration.

  1. workflow:
  2. index:
  3. schedule:
  4. cron: 0/5 * * * *
  5. elements: [...]
  6. tasks: [...]
  1. # Create and run the workflow
  2. from txtai import Application
  3. # Create and run the workflow
  4. app = Application("workflow.yml")
  5. # Wait for scheduled workflows
  6. app.wait()

See the links below for more information on cron expressions.