Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani authored Nov 15, 2024
1 parent 57906e4 commit 719904e
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ The DuckDB Cron extension adds support for scheduled query execution within Duck

> Experimental: USE AT YOUR OWN RISK!

### Cron Runner
```sql
-- Run a query every ten seconds
SELECT cron('SELECT version()', '*/10 * * * * *') AS job_id;
-- Every 15 seconds during hours 1-4
SELECT cron('SELECT now()', '*/15 * 1-4 * * *');

-- Every 2 hours (at minute 0, second 0) during hours 1-4
SELECT cron('SELECT version()', '0 0 */2 1-4 * *');

-- Run a query every hour at minute 0
SELECT cron('SELECT now()', '0 * * * * *') AS job_id;
-- Every Monday through Friday at 7:00:00 AM
SELECT cron('SELECT cleanup()', '0 0 7 ? * MON-FRI');
```

The function returns a job ID that can be used to manage the scheduled task.
Expand All @@ -26,6 +28,38 @@ The function returns a job ID that can be used to manage the scheduled task.
└──────────┘
```

#### Supported Expressions
The extension uses six-field cron expressions:
```
┌───────────── second (0 - 59)
│ ┌───────────── minute (0 - 59)
│ │ ┌───────────── hour (0 - 23)
│ │ │ ┌───────────── day of month (1 - 31)
│ │ │ │ ┌───────────── month (1 - 12)
│ │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday)
│ │ │ │ │ │
* * * * * *
```

##### Special characters:

- `*`: any value
- `?`: no specific value (used in day-of-month/day-of-week)
- `,`: value list separator
- `-`: range of values
- `/`: step values
- `MON-SUN`: named weekdays (case sensitive)

##### Common Patterns:
```
0 0 * * * *: Top of every hour
0 */15 * * * *: Every 15 minutes
0 0 0 * * *: Once per day at midnight
0 0 12 ? * MON-FRI: Weekdays at noon
0 0 0 1 * ?: First day of every month
```


### Listing Jobs
Use the cron_jobs() table function to view all scheduled jobs and their status:
```sql
Expand All @@ -41,7 +75,7 @@ SELECT * FROM cron_jobs();

Returns:

- `job_id``: Unique identifier for the job
- `job_id`: Unique identifier for the job
- `query`: The SQL query to execute
- `schedule`: The cron expression
- `next_run`: Next scheduled execution time
Expand Down

0 comments on commit 719904e

Please sign in to comment.