| 59 | 59 | | |
| 60 | 60 | | /// The most workflow files read from a repository. |
| 61 | 61 | | pub const MAX_WORKFLOWS: usize = 50; |
| 62 | | − | /// Jobs one workspace may have running at once; the rest wait their turn. |
| 62 | + | /// Jobs on g1t's own machines one workspace may always have running at |
| 63 | + | /// once; the rest wait their turn, unless the pool has room (`has_room`). |
| 63 | 64 | | pub const RUNNING_PER_WORKSPACE: u32 = 4; |
| 65 | + | /// The most one workspace may run at once while the pool has room to spare. |
| 66 | + | pub const BURST_PER_WORKSPACE: u32 = 12; |
| 67 | + | /// Sandboxes g1t's own machines have between them (services/runner's |
| 68 | + | /// wrangler.jsonc: 20 standard, 10 g1t-2core, 10 g1t-4core). |
| 69 | + | pub const HOSTED_POOL: u32 = 40; |
| 70 | + | /// Kept free while workspaces run past their share, so another workspace's |
| 71 | + | /// first jobs still start at once. |
| 72 | + | pub const POOL_HEADROOM: u32 = 8; |
| 73 | + | |
| 74 | + | /// Whether a workspace running `in_workspace` jobs on g1t's machines may |
| 75 | + | /// start another while `in_pool` run across every workspace: always within |
| 76 | + | /// its share, and past it, up to the burst, while the pool keeps its |
| 77 | + | /// headroom. |
| 78 | + | pub fn has_room(in_workspace: u32, in_pool: u32) -> bool { |
| 79 | + | in_workspace < RUNNING_PER_WORKSPACE |
| 80 | + | || (in_workspace < BURST_PER_WORKSPACE && in_pool + POOL_HEADROOM < HOSTED_POOL) |
| 81 | + | } |
| 64 | 82 | | /// The longest a job on g1t's own machines may run, whatever its |
| 65 | 83 | | /// `timeout-minutes`. |
| 66 | 84 | | pub const MAX_TIMEOUT_MINUTES: u32 = g1t_actions::workflow::HOSTED_MAX_TIMEOUT_MINUTES; |
| ⋯ |
| 404 | 422 | | Err(error) => worker::console_error!("actions: could not start: {error}"), |
| 405 | 423 | | } |
| 406 | 424 | | } |
| 425 | + | |
| 426 | + | #[cfg(test)] |
| 427 | + | mod room_tests { |
| 428 | + | use super::*; |
| 429 | + | |
| 430 | + | #[test] |
| 431 | + | fn a_workspace_always_has_its_share() { |
| 432 | + | assert!(has_room(RUNNING_PER_WORKSPACE - 1, HOSTED_POOL)); |
| 433 | + | assert!(!has_room(RUNNING_PER_WORKSPACE, HOSTED_POOL)); |
| 434 | + | } |
| 435 | + | |
| 436 | + | #[test] |
| 437 | + | fn past_its_share_a_workspace_runs_more_while_the_pool_keeps_its_headroom() { |
| 438 | + | assert!(has_room(RUNNING_PER_WORKSPACE, HOSTED_POOL - POOL_HEADROOM - 1)); |
| 439 | + | assert!(!has_room(RUNNING_PER_WORKSPACE, HOSTED_POOL - POOL_HEADROOM)); |
| 440 | + | assert!(!has_room(BURST_PER_WORKSPACE, 0)); |
| 441 | + | } |
| 442 | + | } |