Yevhenii Shcherbina
0f6ca55238
feat: implement scheduling mechanism for prebuilds ( #18126 )
...
Closes https://github.com/coder/internal/issues/312
Depends on https://github.com/coder/terraform-provider-coder/pull/408
This PR adds support for defining an **autoscaling block** for
prebuilds, allowing number of desired instances to scale dynamically
based on a schedule.
Example usage:
```
data "coder_workspace_preset" "us-nix" {
...
prebuilds = {
instances = 0 # default to 0 instances
scheduling = {
timezone = "UTC" # a single timezone is used for simplicity
# Scale to 3 instances during the work week
schedule {
cron = "* 8-18 * * 1-5" # from 8AM–6:59PM, Mon–Fri, UTC
instances = 3 # scale to 3 instances
}
# Scale to 1 instance on Saturdays for urgent support queries
schedule {
cron = "* 8-14 * * 6" # from 8AM–2:59PM, Sat, UTC
instances = 1 # scale to 1 instance
}
}
}
}
```
### Behavior
- Multiple `schedule` blocks per `prebuilds` block are supported.
- If the current time matches any defined autoscaling schedule, the
corresponding number of instances is used.
- If no schedule matches, the **default instance count**
(`prebuilds.instances`) is used as a fallback.
### Why
This feature allows prebuild instance capacity to adapt to predictable
usage patterns, such as:
- Scaling up during business hours or high-demand periods
- Reducing capacity during off-hours to save resources
### Cron specification
The cron specification is interpreted as a **continuous time range.**
For example, the expression:
```
* 9-18 * * 1-5
```
is intended to represent a continuous range from **09:00 to 18:59**,
Monday through Friday.
However, due to minor implementation imprecision, it is currently
interpreted as a range from **08:59:00 to 18:58:59**, Monday through
Friday.
This slight discrepancy arises because the evaluation is based on
whether a specific **point in time** falls within the range, using the
`github.com/coder/coder/v2/coderd/schedule/cron` library, which performs
per-minute matching rather than strict range evaluation.
---------
Co-authored-by: Danny Kopping <danny@coder.com >
2025-06-19 11:08:48 -04:00
..
2025-06-19 11:08:48 -04:00
2023-12-02 11:35:25 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-07-19 23:43:10 +10:00
2023-12-02 11:38:12 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-02 11:40:23 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-07-06 16:44:29 -05:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-04-06 16:16:53 -05:00
2023-04-06 16:16:53 -05:00
2023-04-10 14:29:59 -05:00
2023-04-10 14:29:59 -05:00
2023-04-12 11:46:16 -07:00
2023-04-12 11:46:16 -07:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-05-03 23:02:35 +00:00
2023-05-03 23:02:35 +00:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-06-14 12:48:43 -05:00
2025-03-18 14:47:30 +02:00
2023-06-16 17:14:22 +03:00
2023-06-16 17:14:22 +03:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-06-30 12:41:55 +02:00
2023-06-30 12:41:55 +02:00
2023-06-30 13:12:40 +00:00
2023-06-30 13:12:40 +00:00
2023-07-02 21:29:52 -05:00
2023-12-01 16:11:10 -06:00
2023-07-07 14:14:29 +02:00
2023-07-07 14:14:29 +02:00
2023-07-10 13:44:03 +02:00
2023-07-10 13:44:03 +02:00
2023-07-11 13:11:08 +03:00
2023-07-11 13:11:08 +03:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-07-20 22:01:11 -05:00
2023-07-20 22:01:11 -05:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-08-02 16:31:25 +02:00
2023-08-02 16:31:25 +02:00
2023-08-02 15:09:10 +00:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-08-16 15:22:00 +03:00
2023-08-16 15:22:00 +03:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-09-06 12:06:26 +01:00
2023-09-18 11:07:54 +01:00
2023-09-18 11:07:54 +01:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-10-03 11:13:44 +00:00
2023-10-03 11:13:44 +00:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-10-05 14:49:08 +02:00
2023-10-05 14:49:08 +02:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-10-09 18:49:30 -05:00
2023-10-09 18:49:30 -05:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-12-01 16:11:10 -06:00
2023-11-28 18:15:17 +01:00
2023-11-28 18:15:17 +01:00
2023-12-05 13:54:38 +00:00
2023-12-05 13:54:38 +00:00
2023-12-07 17:11:57 -06:00
2023-12-07 17:11:57 -06:00
2023-12-08 21:59:53 +00:00
2023-12-08 21:59:53 +00:00
2023-12-11 10:09:51 -07:00
2023-12-11 10:09:51 -07:00
2023-12-12 11:19:28 +00:00
2023-12-12 11:19:28 +00:00
2023-12-13 12:31:40 +00:00
2023-12-13 12:31:40 +00:00
2023-12-14 12:52:41 +00:00
2023-12-14 12:52:41 +00:00
2023-12-15 18:27:56 +10:00
2023-12-15 18:27:56 +10:00
2023-12-18 16:44:52 +00:00
2023-12-18 16:44:52 +00:00
2023-12-21 21:38:42 +00:00
2023-12-21 21:38:42 +00:00
2024-01-03 14:11:02 +00:00
2024-01-03 14:11:02 +00:00
2024-01-04 11:47:31 +00:00
2024-01-04 11:47:31 +00:00
2024-01-17 13:20:45 +01:00
2024-01-17 13:20:45 +01:00
2024-01-24 13:39:19 +00:00
2024-01-24 13:39:19 +00:00
2024-01-29 19:30:02 -06:00
2024-01-29 19:30:02 -06:00
2024-02-08 17:29:34 +01:00
2024-02-08 17:29:34 +01:00
2024-02-12 15:11:31 +01:00
2024-02-12 15:11:31 +01:00
2024-02-13 07:00:35 +00:00
2024-02-13 07:00:35 +00:00
2024-02-13 09:31:20 -05:00
2024-02-13 09:31:20 -05:00
2024-02-15 13:33:13 +01:00
2024-02-15 13:33:13 +01:00
2024-02-15 11:01:16 -06:00
2024-02-15 11:01:16 -06:00
2024-02-20 13:19:38 -06:00
2024-02-20 13:19:38 -06:00
2024-02-20 14:58:43 -09:00
2025-03-25 12:18:06 +00:00
2024-04-18 18:47:02 -05:00
2024-03-16 10:11:14 -04:00
2024-02-26 23:52:08 +00:00
2024-02-26 23:52:08 +00:00
2024-03-05 14:06:35 -06:00
2024-03-05 14:06:35 -06:00
2024-03-06 09:23:57 -05:00
2024-03-06 09:23:57 -05:00
2024-03-06 18:28:53 +00:00
2024-03-06 18:28:53 +00:00
2024-03-12 14:55:45 +00:00
2024-03-12 14:55:45 +00:00
2024-03-20 10:37:57 -05:00
2024-03-20 10:37:57 -05:00
2024-03-22 18:33:34 +02:00
2024-03-22 18:33:34 +02:00
2024-03-28 14:31:58 +02:00
2024-03-28 14:31:58 +02:00
2024-04-03 13:17:11 -05:00
2024-04-03 13:17:11 -05:00
2024-04-11 10:05:53 +04:00
2024-04-11 10:05:53 +04:00
2024-04-22 17:25:36 -06:00
2024-04-22 17:25:36 -06:00
2024-05-08 15:40:43 -06:00
2024-05-08 15:40:43 -06:00
2024-05-16 13:11:26 -05:00
2024-05-16 13:11:26 -05:00
2024-05-17 12:40:38 -06:00
2024-05-17 12:40:38 -06:00
2024-05-20 13:30:19 +00:00
2024-05-20 13:30:19 +00:00
2024-05-21 13:14:00 -05:00
2024-05-21 13:14:00 -05:00
2024-05-31 10:59:28 -06:00
2024-05-31 10:59:28 -06:00
2024-06-04 09:27:44 -05:00
2024-06-04 09:27:44 -05:00
2024-06-05 11:25:02 -05:00
2024-06-05 11:25:02 -05:00
2024-06-06 10:59:59 -06:00
2024-06-06 10:59:59 -06:00
2024-06-06 16:13:00 -05:00
2024-06-06 16:13:00 -05:00
2024-06-07 14:11:57 -05:00
2024-06-07 14:11:57 -05:00
2024-06-12 12:28:13 -06:00
2024-06-12 12:28:13 -06:00
2024-06-24 14:19:32 -05:00
2024-06-24 14:19:32 -05:00
2024-06-28 09:21:25 +00:00
2024-07-08 15:38:50 +02:00
2024-07-02 09:08:30 -05:00
2024-07-02 09:08:30 -05:00
2024-07-10 16:15:06 +02:00
2024-07-10 16:15:06 +02:00
2024-07-10 10:06:49 -05:00
2024-07-10 10:06:49 -05:00
2024-07-11 10:57:49 +02:00
2024-07-11 10:57:49 +02:00
2024-07-16 10:48:17 +02:00
2024-07-16 10:48:17 +02:00
2024-07-16 13:27:12 -04:00
2024-07-16 13:27:12 -04:00
2024-07-18 15:19:12 +02:00
2024-07-18 15:19:12 +02:00
2024-07-24 13:38:21 -03:00
2024-07-24 13:38:21 -03:00
2024-07-25 12:02:24 +02:00
2024-07-25 12:02:24 +02:00
2024-07-25 15:20:45 +00:00
2024-07-25 15:20:45 +00:00
2024-07-29 11:20:04 -03:00
2024-07-29 11:20:04 -03:00
2024-07-30 15:37:45 +02:00
2024-07-30 15:37:45 +02:00
2024-08-02 11:03:11 +02:00
2024-08-02 11:03:11 +02:00
2024-08-02 10:00:27 +00:00
2024-08-02 10:00:27 +00:00
2024-08-02 14:56:54 +02:00
2024-08-02 14:56:54 +02:00
2024-08-02 12:49:36 -04:00
2024-08-02 12:49:36 -04:00
2024-08-05 16:18:45 +02:00
2024-08-05 16:18:45 +02:00
2024-08-06 11:38:55 -04:00
2024-08-06 11:38:55 -04:00
2024-08-07 11:33:26 +02:00
2024-08-07 11:33:26 +02:00
2024-08-07 12:37:55 -05:00
2024-08-07 12:37:55 -05:00
2024-08-13 09:20:24 -05:00
2024-08-13 09:20:24 -05:00
2024-08-13 12:53:47 -05:00
2024-08-13 12:53:47 -05:00
2024-09-03 13:04:06 +02:00
2024-08-14 14:22:43 -03:00
2024-08-21 11:18:03 +02:00
2024-08-21 11:18:03 +02:00
2024-08-21 12:46:11 +00:00
2024-08-21 12:46:11 +00:00
2024-08-22 13:52:25 +02:00
2024-08-22 13:52:25 +02:00
2024-08-27 14:35:28 +00:00
2024-08-27 14:35:28 +00:00
2024-09-09 14:39:32 +01:00
2024-09-09 14:39:32 +01:00
2024-09-16 20:02:08 +00:00
2024-09-16 20:02:08 +00:00
2024-09-17 18:08:18 +01:00
2024-09-17 18:08:18 +01:00
2024-09-17 19:41:34 -05:00
2024-09-17 19:41:34 -05:00
2024-09-18 09:11:44 +02:00
2024-09-18 09:11:44 +02:00
2024-09-18 11:26:34 +00:00
2024-09-18 11:26:34 +00:00
2024-09-20 01:52:14 +10:00
2024-09-20 01:52:14 +10:00
2024-09-20 14:26:13 +01:00
2024-09-20 14:26:13 +01:00
2024-09-24 10:51:49 +01:00
2024-09-24 10:51:49 +01:00
2024-09-25 17:46:51 +01:00
2024-09-25 17:46:51 +01:00
2024-09-26 13:20:44 -05:00
2024-09-26 13:20:44 -05:00
2024-10-02 09:30:33 -06:00
2024-10-02 09:30:33 -06:00
2024-10-04 11:53:25 +01:00
2024-10-04 11:53:25 +01:00
2024-10-09 17:31:12 -05:00
2024-10-09 17:31:12 -05:00
2024-10-14 12:34:32 +00:00
2024-10-14 12:34:32 +00:00
2024-10-15 21:02:02 +02:00
2024-10-15 21:02:02 +02:00
2024-10-16 21:53:24 +02:00
2024-10-16 21:53:24 +02:00
2024-10-18 09:50:22 -03:00
2024-10-18 09:50:22 -03:00
2024-10-21 16:09:59 +01:00
2024-10-21 16:09:59 +01:00
2024-10-22 13:47:30 +01:00
2024-10-22 13:47:30 +01:00
2024-10-22 09:20:54 -05:00
2024-10-22 09:20:54 -05:00
2024-10-24 13:12:12 +01:00
2024-10-24 13:12:12 +01:00
2024-10-25 17:14:35 +01:00
2024-10-25 17:14:35 +01:00
2024-10-29 09:57:40 +00:00
2024-10-29 09:57:40 +00:00
2024-11-01 14:36:12 +11:00
2024-11-01 14:36:12 +11:00
2024-11-15 11:39:05 +00:00
2024-11-15 11:39:05 +00:00
2024-11-15 11:39:05 +00:00
2024-11-15 11:39:05 +00:00
2024-11-16 21:56:19 +01:00
2024-11-16 21:56:19 +01:00
2024-11-27 20:01:08 +01:00
2024-11-27 20:01:08 +01:00
2024-12-02 21:02:36 +00:00
2024-12-02 21:02:36 +00:00
2024-12-20 13:53:10 +00:00
2024-12-20 13:53:10 +00:00
2025-01-02 12:19:34 +00:00
2025-01-02 12:19:34 +00:00
2025-01-02 15:02:04 -06:00
2025-01-02 15:02:04 -06:00
2025-01-03 11:27:02 +01:00
2025-01-03 11:27:02 +01:00
2025-01-13 13:08:16 +02:00
2025-01-13 13:08:16 +02:00
2025-01-13 15:01:47 +00:00
2025-01-13 15:01:47 +00:00
2025-01-13 15:01:47 +00:00
2025-01-13 15:01:47 +00:00
2025-01-14 16:40:26 +00:00
2025-01-14 16:40:26 +00:00
2025-01-17 11:55:41 -06:00
2025-01-17 11:55:41 -06:00
2025-01-31 13:55:46 +01:00
2025-01-31 13:55:46 +01:00
2025-02-04 18:45:33 +01:00
2025-02-04 18:45:33 +01:00
2025-02-04 19:25:18 +00:00
2025-02-04 19:25:18 +00:00
2025-02-11 13:55:09 +02:00
2025-02-11 13:55:09 +02:00
2025-02-12 14:41:14 +02:00
2025-02-12 14:41:14 +02:00
2025-02-17 13:02:30 +00:00
2025-02-17 13:02:30 +00:00
2025-02-17 16:56:52 +00:00
2025-02-17 16:56:52 +00:00
2025-02-19 13:08:38 +00:00
2025-02-19 13:08:38 +00:00
2025-02-24 12:59:41 -05:00
2025-02-24 12:59:41 -05:00
2025-03-03 10:12:48 +01:00
2025-03-03 10:12:48 +01:00
2025-03-03 10:02:18 -05:00
2025-03-03 10:02:18 -05:00
2025-03-05 10:46:03 -07:00
2025-03-05 10:46:03 -07:00
2025-03-05 23:13:42 +01:00
2025-03-05 23:13:42 +01:00
2025-03-18 13:50:52 +02:00
2025-03-18 13:50:52 +02:00
2025-03-20 14:10:45 +00:00
2025-03-20 14:10:45 +00:00
2025-03-20 19:09:39 +02:00
2025-03-20 19:09:39 +02:00
2025-03-21 13:31:17 +01:00
2025-03-21 13:31:17 +01:00
2025-03-21 16:05:08 +01:00
2025-03-21 16:05:08 +01:00
2025-03-24 10:01:50 -06:00
2025-03-24 10:01:50 -06:00
2025-03-25 11:29:02 +01:00
2025-03-25 11:29:02 +01:00
2025-03-25 12:18:06 +00:00
2025-03-25 12:18:06 +00:00
2025-03-25 12:59:20 +00:00
2025-03-25 12:59:20 +00:00
2025-03-25 15:31:24 -04:00
2025-03-25 15:31:24 -04:00
2025-03-26 15:54:03 +01:00
2025-03-26 15:54:03 +01:00
2025-03-27 10:03:53 +00:00
2025-03-27 10:03:53 +00:00
2025-03-31 10:55:44 -04:00
2025-03-31 10:55:44 -04:00
2025-04-03 10:58:30 +02:00
2025-04-03 10:58:30 +02:00
2025-04-03 10:58:30 +02:00
2025-04-03 10:58:30 +02:00
2025-04-10 13:32:19 +01:00
2025-04-10 13:32:19 +01:00
2025-04-15 10:47:42 +01:00
2025-04-15 10:47:42 +01:00
2025-05-01 13:26:01 -03:00
2025-05-01 13:26:01 -03:00
2025-05-02 17:29:57 +01:00
2025-05-02 17:29:57 +01:00
2025-05-12 13:50:07 -06:00
2025-05-12 13:50:07 -06:00
2025-05-13 00:01:31 +01:00
2025-05-13 00:01:31 +01:00
2025-05-13 13:52:55 +01:00
2025-05-13 13:52:55 +01:00
2025-05-13 20:51:01 +02:00
2025-05-13 20:51:01 +02:00
2025-05-14 14:52:22 +02:00
2025-05-14 14:52:22 +02:00
2025-05-14 12:21:36 -05:00
2025-05-14 12:21:36 -05:00
2025-05-15 15:32:52 +01:00
2025-05-15 15:32:52 +01:00
2025-05-15 17:55:17 -05:00
2025-05-15 17:55:17 -05:00
2025-05-21 15:16:38 -04:00
2025-05-21 15:16:38 -04:00
2025-05-21 15:16:38 -04:00
2025-05-21 15:16:38 -04:00
2025-05-27 11:42:07 -03:00
2025-05-27 11:42:07 -03:00
2025-05-27 13:13:08 -06:00
2025-05-27 13:13:08 -06:00
2025-05-28 14:21:17 +01:00
2025-05-28 14:21:17 +01:00
2025-05-29 08:55:19 -05:00
2025-05-29 08:55:19 -05:00
2025-06-12 12:15:05 -04:00
2025-06-12 12:15:05 -04:00
2025-06-13 15:54:02 +02:00
2025-06-13 15:54:02 +02:00
2025-06-16 16:15:59 -06:00
2025-06-16 16:15:59 -06:00
2025-06-17 16:08:34 +02:00
2025-06-17 16:08:34 +02:00
2025-06-19 13:32:51 +00:00
2025-06-19 13:32:51 +00:00
2025-06-19 11:08:48 -04:00
2025-06-19 11:08:48 -04:00
2023-12-08 21:59:53 +00:00
2025-03-06 12:21:14 +02:00
2025-06-12 13:56:45 -04:00
2024-11-04 17:23:31 +01:00
2023-12-01 16:11:10 -06:00