schedule.md
1 # Schedule 2 3  4  5 6 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. 7 8 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. 9 10 Below are a couple example cron expressions. 11 12 ```bash 13 # ┌─────────────── minute (0 - 59) 14 # | ┌───────────── hour (0 - 23) 15 # | | ┌─────────── day of the month (1 - 31) 16 # | | | ┌───────── month (1 - 12) 17 # | | | | ┌─────── day of the week (0 - 6) 18 # | | | | | ┌───── second (0 - 59) 19 # | | | | | | 20 * * * * * * # Run every second 21 0/5 * * * * # Run every 5 minutes 22 0 0 1 * * # Run monthly on 1st 23 0 0 1 1 * # Run on Jan 1 at 12am 24 0 0 * * mon,wed # Run Monday and Wednesday 25 ``` 26 27 ## Python 28 Simple workflow [scheduled](../#txtai.workflow.base.Workflow.schedule) with Python. 29 30 ```python 31 workflow = Workflow(tasks) 32 workflow.schedule("0/5 * * * *", elements) 33 ``` 34 35 See the link below for a more detailed example. 36 37 | Notebook | Description | | 38 |:----------|:-------------|------:| 39 | [Workflow Scheduling](https://github.com/neuml/txtai/blob/master/examples/27_Workflow_scheduling.ipynb) | Schedule workflows with cron expressions | [](https://colab.research.google.com/github/neuml/txtai/blob/master/examples/27_Workflow_scheduling.ipynb) | 40 41 ## Configuration 42 Simple workflow scheduled with configuration. 43 44 ```yaml 45 workflow: 46 index: 47 schedule: 48 cron: 0/5 * * * * 49 elements: [...] 50 tasks: [...] 51 ``` 52 53 ```python 54 # Create and run the workflow 55 from txtai import Application 56 57 # Create and run the workflow 58 app = Application("workflow.yml") 59 60 # Wait for scheduled workflows 61 app.wait() 62 ``` 63 64 See the links below for more information on cron expressions. 65 66 - [cron overview](https://en.wikipedia.org/wiki/Cron) 67 - [croniter - library used by txtai](https://github.com/kiorky/croniter)