@@ -5,14 +5,16 @@ The DuckDB Cron extension adds support for scheduled query execution within Duck
5
5
6
6
> Experimental: USE AT YOUR OWN RISK!
7
7
8
-
9
8
### Cron Runner
10
9
``` sql
11
- -- Run a query every ten seconds
12
- SELECT cron(' SELECT version()' , ' */10 * * * * *' ) AS job_id;
10
+ -- Every 15 seconds during hours 1-4
11
+ SELECT cron(' SELECT now()' , ' */15 * 1-4 * * *' );
12
+
13
+ -- Every 2 hours (at minute 0, second 0) during hours 1-4
14
+ SELECT cron(' SELECT version()' , ' 0 0 */2 1-4 * *' );
13
15
14
- -- Run a query every hour at minute 0
15
- SELECT cron(' SELECT now ()' , ' 0 * * * * * ' ) AS job_id ;
16
+ -- Every Monday through Friday at 7:00:00 AM
17
+ SELECT cron(' SELECT cleanup ()' , ' 0 0 7 ? * MON-FRI ' ) ;
16
18
```
17
19
18
20
The function returns a job ID that can be used to manage the scheduled task.
@@ -26,6 +28,38 @@ The function returns a job ID that can be used to manage the scheduled task.
26
28
└──────────┘
27
29
```
28
30
31
+ #### Supported Expressions
32
+ The extension uses six-field cron expressions:
33
+ ```
34
+ ┌───────────── second (0 - 59)
35
+ │ ┌───────────── minute (0 - 59)
36
+ │ │ ┌───────────── hour (0 - 23)
37
+ │ │ │ ┌───────────── day of month (1 - 31)
38
+ │ │ │ │ ┌───────────── month (1 - 12)
39
+ │ │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday)
40
+ │ │ │ │ │ │
41
+ * * * * * *
42
+ ```
43
+
44
+ ##### Special characters:
45
+
46
+ - ` * ` : any value
47
+ - ` ? ` : no specific value (used in day-of-month/day-of-week)
48
+ - ` , ` : value list separator
49
+ - ` - ` : range of values
50
+ - ` / ` : step values
51
+ - ` MON-SUN ` : named weekdays (case sensitive)
52
+
53
+ ##### Common Patterns:
54
+ ```
55
+ 0 0 * * * *: Top of every hour
56
+ 0 */15 * * * *: Every 15 minutes
57
+ 0 0 0 * * *: Once per day at midnight
58
+ 0 0 12 ? * MON-FRI: Weekdays at noon
59
+ 0 0 0 1 * ?: First day of every month
60
+ ```
61
+
62
+
29
63
### Listing Jobs
30
64
Use the cron_jobs() table function to view all scheduled jobs and their status:
31
65
``` sql
@@ -41,7 +75,7 @@ SELECT * FROM cron_jobs();
41
75
42
76
Returns:
43
77
44
- - `job_id`` : Unique identifier for the job
78
+ - ` job_id ` : Unique identifier for the job
45
79
- ` query ` : The SQL query to execute
46
80
- ` schedule ` : The cron expression
47
81
- ` next_run ` : Next scheduled execution time
0 commit comments