| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | | use super::{now_ms, Pool}; |
| 5 | | use sqlx::FromRow; |
| 6 | |
|
| 7 | | #[derive(Clone, Debug, Default, FromRow)] |
| 8 | | pub struct Runner { |
| 9 | | pub id: i64, |
| 10 | | pub name: String, |
| 11 | | pub token_hash: String, |
| 12 | | pub source: String, |
| 13 | | pub key: String, |
| 14 | | pub key_name: String, |
| 15 | | pub arch: String, |
| 16 | | pub os: String, |
| 17 | | pub version: String, |
| 18 | | pub labels: String, |
| 19 | | pub max_jobs: i64, |
| 20 | | pub memory_mib: Option<i64>, |
| 21 | | pub cpus: Option<i64>, |
| 22 | | pub state: String, |
| 23 | | pub created_ms: i64, |
| 24 | | pub created_by: String, |
| 25 | | pub last_seen_ms: Option<i64>, |
| 26 | | |
| 27 | | pub scope_owner: String, |
| 28 | | |
| 29 | | pub scope_repo_id: Option<i64>, |
| 30 | | |
| 31 | | pub admin_labels: String, |
| 32 | | |
| 33 | | pub timeout_minutes: Option<i64>, |
| 34 | | |
| 35 | | pub fetches_images: bool, |
| 36 | | |
| 37 | | |
| 38 | | pub free_disk_mib: Option<i64>, |
| 39 | | pub load_x100: Option<i64>, |
| 40 | | pub speed: Option<i64>, |
| 41 | | pub speed_class: Option<i64>, |
| 42 | | pub kernel: String, |
| 43 | | |
| 44 | | pub tiers: String, |
| 45 | | |
| 46 | | pub images: String, |
| 47 | | |
| 48 | | pub profile: String, |
| 49 | | |
| 50 | | pub update_note: String, |
| 51 | | pub update_ms: Option<i64>, |
| 52 | | } |
| 53 | |
|
| 54 | |
|
| 55 | | #[derive(Clone, Debug, Default, PartialEq, Eq)] |
| 56 | | pub struct Scope { |
| 57 | | |
| 58 | | pub owner: String, |
| 59 | | |
| 60 | | pub repo_id: Option<i64>, |
| 61 | | } |
| 62 | |
|
| 63 | | impl Scope { |
| 64 | 6× | pub fn is_site(&self) -> bool { |
| 65 | 6× | self.owner.is_empty() && self.repo_id.is_none() |
| 66 | 6× | } |
| 67 | | } |
| 68 | |
|
| 69 | |
|
| 70 | | pub const ONLINE_MS: i64 = 90_000; |
| 71 | |
|
| 72 | | impl Runner { |
| 73 | 489× | pub fn online(&self) -> bool { |
| 74 | 489× | self.last_seen_ms.is_some_and(|t| now_ms() - t < ONLINE_MS) |
| 75 | 489× | } |
| 76 | |
|
| 77 | | |
| 78 | | |
| 79 | 39× | pub fn connectivity(&self) -> &'static str { |
| 80 | 39× | if self.online() { |
| 81 | 37× | "online" |
| 82 | | } else { |
| 83 | 2× | "offline" |
| 84 | | } |
| 85 | 39× | } |
| 86 | |
|
| 87 | | |
| 88 | 88× | pub fn status(&self) -> &'static str { |
| 89 | 88× | match self.state.as_str() { |
| 90 | 88× | "disabled" => "disabled", |
| 91 | 88× | "draining" => "draining", |
| 92 | 88× | _ if self.online() => "online", |
| 93 | 0× | _ => "offline", |
| 94 | | } |
| 95 | 88× | } |
| 96 | |
|
| 97 | | |
| 98 | | |
| 99 | 61× | pub fn label_list(&self) -> Vec<&str> { |
| 100 | 61× | let mut out: Vec<&str> = self.labels.split(',').filter(|l| !l.is_empty()).collect(); |
| 101 | 61× | for l in self.admin_label_list() { |
| 102 | 10× | if !out.contains(&l) { |
| 103 | 10× | out.push(l); |
| 104 | 10× | } |
| 105 | | } |
| 106 | 61× | out |
| 107 | 61× | } |
| 108 | |
|
| 109 | 293× | pub fn admin_label_list(&self) -> Vec<&str> { |
| 110 | 300× | self.admin_labels.split(',').filter(|l| !l.is_empty()).collect() |
| 111 | 293× | } |
| 112 | |
|
| 113 | | |
| 114 | 221× | pub fn reported_label_list(&self) -> Vec<&str> { |
| 115 | 221× | self.labels.split(',').filter(|l| !l.is_empty()).collect() |
| 116 | 221× | } |
| 117 | |
|
| 118 | 293× | pub fn scope(&self) -> Scope { |
| 119 | 293× | Scope { owner: self.scope_owner.clone(), repo_id: self.scope_repo_id } |
| 120 | 293× | } |
| 121 | | } |
| 122 | |
|
| 123 | 488× | pub async fn by_token(pool: &Pool, token_hash: &str) -> sqlx::Result<Option<Runner>> { |
| 124 | 488× | sqlx::query_as("SELECT * FROM flow_runners WHERE token_hash = $1").bind(token_hash).fetch_optional(pool).await |
| 125 | 488× | } |
| 126 | |
|
| 127 | 37× | pub async fn get(pool: &Pool, id: i64) -> sqlx::Result<Option<Runner>> { |
| 128 | 37× | sqlx::query_as("SELECT * FROM flow_runners WHERE id = $1").bind(id).fetch_optional(pool).await |
| 129 | 37× | } |
| 130 | |
|
| 131 | 769× | pub async fn list(pool: &Pool) -> sqlx::Result<Vec<Runner>> { |
| 132 | 769× | sqlx::query_as("SELECT * FROM flow_runners ORDER BY name, id").fetch_all(pool).await |
| 133 | 769× | } |
| 134 | |
|
| 135 | |
|
| 136 | 69× | pub async fn configured(pool: &Pool, token_hash: &str, name: &str) -> sqlx::Result<Runner> { |
| 137 | 69× | sqlx::query("INSERT INTO flow_runners (name, token_hash, source, created_ms) VALUES ($1, $2, 'config', $3) ON CONFLICT DO NOTHING") |
| 138 | 69× | .bind(name) |
| 139 | 69× | .bind(token_hash) |
| 140 | 69× | .bind(now_ms()) |
| 141 | 69× | .execute(pool) |
| 142 | 69× | .await?; |
| 143 | 69× | Ok(by_token(pool, token_hash).await?.expect("just made")) |
| 144 | 69× | } |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | 1× | pub async fn set_limits(pool: &Pool, id: i64, admin_labels: &str, timeout_minutes: Option<i64>) -> sqlx::Result<()> { |
| 150 | 1× | sqlx::query("UPDATE flow_runners SET admin_labels = $1, timeout_minutes = $2 WHERE id = $3") |
| 151 | 1× | .bind(admin_labels) |
| 152 | 1× | .bind(timeout_minutes) |
| 153 | 1× | .bind(id) |
| 154 | 1× | .execute(pool) |
| 155 | 1× | .await?; |
| 156 | 1× | Ok(()) |
| 157 | 1× | } |
| 158 | |
|
| 159 | 384× | pub async fn seen(pool: &Pool, id: i64, name: Option<&str>, info: Option<&flow_core::api::RunnerInfo>) -> sqlx::Result<()> { |
| 160 | 384× | let now = now_ms(); |
| 161 | 384× | match info { |
| 162 | 31× | Some(i) => { |
| 163 | 31× | sqlx::query( |
| 164 | 31× | "UPDATE flow_runners SET arch = $1, os = $2, version = $3, labels = $4, max_jobs = $5, memory_mib = $6, cpus = $7, last_seen_ms = $8 WHERE id = $9", |
| 165 | 31× | ) |
| 166 | 31× | .bind(&i.arch) |
| 167 | 31× | .bind(&i.os) |
| 168 | 31× | .bind(&i.version) |
| 169 | 31× | .bind(i.labels.join(",")) |
| 170 | 31× | .bind(i.max_jobs as i64) |
| 171 | 31× | .bind(i.memory_mib.map(i64::from)) |
| 172 | 31× | .bind(i.cpus.map(i64::from)) |
| 173 | 31× | .bind(now) |
| 174 | 31× | .bind(id) |
| 175 | 31× | .execute(pool) |
| 176 | 31× | .await?; |
| 177 | | } |
| 178 | | None => { |
| 179 | 353× | sqlx::query("UPDATE flow_runners SET last_seen_ms = $1 WHERE id = $2").bind(now).bind(id).execute(pool).await?; |
| 180 | | } |
| 181 | | } |
| 182 | 384× | if let Some(n) = name { |
| 183 | 229× | sqlx::query("UPDATE flow_runners SET name = $1 WHERE id = $2 AND source = 'config'").bind(n).bind(id).execute(pool).await?; |
| 184 | 155× | } |
| 185 | 384× | Ok(()) |
| 186 | 384× | } |
| 187 | |
|
| 188 | |
|
| 189 | 13× | pub async fn set_facts(pool: &Pool, id: i64, f: &flow_core::api::Facts) -> sqlx::Result<()> { |
| 190 | 13× | sqlx::query("UPDATE flow_runners SET free_disk_mib = $1, load_x100 = $2, speed = $3, speed_class = $4, kernel = $5 WHERE id = $6") |
| 191 | 13× | .bind(f.free_disk_mib.map(|v| v.min(i64::MAX as u64) as i64)) |
| 192 | 13× | .bind(f.load_x100.map(i64::from)) |
| 193 | 13× | .bind(f.speed.map(i64::from)) |
| 194 | 13× | .bind(f.speed_class.map(i64::from)) |
| 195 | 13× | .bind(f.kernel.clone().unwrap_or_default()) |
| 196 | 13× | .bind(id) |
| 197 | 13× | .execute(pool) |
| 198 | 13× | .await?; |
| 199 | 13× | Ok(()) |
| 200 | 13× | } |
| 201 | |
|
| 202 | | impl Runner { |
| 203 | | |
| 204 | | |
| 205 | 20× | pub fn facts_line(&self) -> String { |
| 206 | 20× | let mut out = Vec::new(); |
| 207 | 20× | if let Some(s) = self.speed { |
| 208 | 1× | out.push(format!("speed {s} (class {})", self.speed_class.unwrap_or(0))); |
| 209 | 19× | } |
| 210 | 20× | if let Some(l) = self.load_x100 { |
| 211 | 1× | out.push(format!("load {:.2}", l as f64 / 100.0)); |
| 212 | 19× | } |
| 213 | 20× | if let Some(d) = self.free_disk_mib { |
| 214 | 1× | out.push(if d >= 1024 { format!("{} GiB free", d / 1024) } else { format!("{d} MiB free") }); |
| 215 | 19× | } |
| 216 | 20× | out.join(" · ") |
| 217 | 20× | } |
| 218 | | } |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | 231× | pub async fn set_offer( |
| 224 | 231× | pool: &Pool, |
| 225 | 231× | id: i64, |
| 226 | 231× | tiers: &[String], |
| 227 | 231× | images: Option<&[String]>, |
| 228 | 231× | fetches_images: bool, |
| 229 | 231× | profile: &str, |
| 230 | 231× | ) -> sqlx::Result<()> { |
| 231 | 231× | let images = images.map(|i| serde_json::to_string(i).unwrap_or_default()).unwrap_or_default(); |
| 232 | 231× | sqlx::query("UPDATE flow_runners SET tiers = $1, images = $2, fetches_images = $3, profile = $4 WHERE id = $5") |
| 233 | 231× | .bind(tiers.join(",")) |
| 234 | 231× | .bind(images) |
| 235 | 231× | .bind(fetches_images) |
| 236 | 231× | .bind(profile) |
| 237 | 231× | .bind(id) |
| 238 | 231× | .execute(pool) |
| 239 | 231× | .await?; |
| 240 | 231× | Ok(()) |
| 241 | 231× | } |
| 242 | |
|
| 243 | | impl Runner { |
| 244 | 44× | pub fn tier_list(&self) -> Vec<&str> { |
| 245 | 51× | self.tiers.split(',').filter(|t| !t.is_empty()).collect() |
| 246 | 44× | } |
| 247 | |
|
| 248 | | |
| 249 | 445× | pub fn image_list(&self) -> Option<Vec<String>> { |
| 250 | 445× | if self.images.is_empty() { |
| 251 | 354× | None |
| 252 | | } else { |
| 253 | 91× | serde_json::from_str(&self.images).ok() |
| 254 | | } |
| 255 | 445× | } |
| 256 | | } |
| 257 | |
|
| 258 | 4× | pub async fn set_state(pool: &Pool, id: i64, state: &str) -> sqlx::Result<()> { |
| 259 | 4× | sqlx::query("UPDATE flow_runners SET state = $1, state_ms = $2 WHERE id = $3") |
| 260 | 4× | .bind(state) |
| 261 | 4× | .bind(super::now_ms()) |
| 262 | 4× | .bind(id) |
| 263 | 4× | .execute(pool) |
| 264 | 4× | .await?; |
| 265 | 4× | Ok(()) |
| 266 | 4× | } |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | 12× | pub async fn erroring(pool: &Pool, id: i64, n: u32) -> sqlx::Result<Option<String>> { |
| 271 | 12× | if n == 0 { |
| 272 | 0× | return Ok(None); |
| 273 | 12× | } |
| 274 | 12× | let last: Vec<(String, String)> = sqlx::query_as( |
| 275 | 12× | "SELECT j.status, j.error FROM flow_jobs j JOIN flow_runners r ON r.id = j.runner_id |
| 276 | 12× | WHERE j.runner_id = $1 AND j.finished_ms IS NOT NULL AND j.finished_ms >= r.state_ms |
| 277 | 12× | ORDER BY j.finished_ms DESC, j.id DESC LIMIT $2", |
| 278 | 12× | ) |
| 279 | 12× | .bind(id) |
| 280 | 12× | .bind(n as i64) |
| 281 | 12× | .fetch_all(pool) |
| 282 | 12× | .await?; |
| 283 | 17× | Ok((last.len() == n as usize && last.iter().all(|(s, _)| s == "error")).then(|| last[0].1.clone())) |
| 284 | 12× | } |
| 285 | |
|
| 286 | |
|
| 287 | 3× | pub async fn remove(pool: &Pool, id: i64) -> sqlx::Result<()> { |
| 288 | 3× | sqlx::query("DELETE FROM runner_group_members WHERE runner_id = $1").bind(id).execute(pool).await?; |
| 289 | 3× | sqlx::query("DELETE FROM runner_update_policies WHERE scope = 'runner' AND key = $1").bind(id.to_string()).execute(pool).await?; |
| 290 | 3× | sqlx::query("DELETE FROM flow_runners WHERE id = $1").bind(id).execute(pool).await?; |
| 291 | 3× | Ok(()) |
| 292 | 3× | } |
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | 6× | pub async fn bind_key(pool: &Pool, id: i64, key: &str, name: &str) -> sqlx::Result<String> { |
| 297 | 6× | sqlx::query("UPDATE flow_runners SET key = $1, key_name = $2 WHERE id = $3 AND key = ''") |
| 298 | 6× | .bind(key) |
| 299 | 6× | .bind(name) |
| 300 | 6× | .bind(id) |
| 301 | 6× | .execute(pool) |
| 302 | 6× | .await?; |
| 303 | 6× | sqlx::query_scalar("SELECT key FROM flow_runners WHERE id = $1").bind(id).fetch_one(pool).await |
| 304 | 6× | } |
| 305 | |
|
| 306 | |
|
| 307 | 5× | pub async fn keys(pool: &Pool) -> sqlx::Result<Vec<String>> { |
| 308 | 5× | sqlx::query_scalar("SELECT key FROM flow_runners WHERE key != ''").fetch_all(pool).await |
| 309 | 5× | } |
| 310 | |
|
| 311 | |
|
| 312 | 17× | pub async fn add_registration(pool: &Pool, token_hash: &str, by: &str, scope: &Scope) -> sqlx::Result<()> { |
| 313 | 17× | let now = now_ms(); |
| 314 | 17× | sqlx::query( |
| 315 | 17× | "INSERT INTO flow_runner_registrations (token_hash, created_by, created_ms, expires_ms, scope_owner, scope_repo_id) VALUES ($1, $2, $3, $4, $5, $6)", |
| 316 | 17× | ) |
| 317 | 17× | .bind(token_hash) |
| 318 | 17× | .bind(by) |
| 319 | 17× | .bind(now) |
| 320 | 17× | .bind(now + 24 * 3_600_000) |
| 321 | 17× | .bind(&scope.owner) |
| 322 | 17× | .bind(scope.repo_id) |
| 323 | 17× | .execute(pool) |
| 324 | 17× | .await?; |
| 325 | 17× | Ok(()) |
| 326 | 17× | } |
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | 268× | pub async fn serving(pool: &Pool, owner: &str, repo_id: i64) -> sqlx::Result<Vec<Runner>> { |
| 331 | 268× | sqlx::query_as( |
| 332 | 268× | "SELECT * FROM flow_runners WHERE (scope_owner = '' AND scope_repo_id IS NULL) \ |
| 333 | 268× | OR (scope_owner = $1 AND scope_repo_id IS NULL) OR scope_repo_id = $2 ORDER BY name", |
| 334 | 268× | ) |
| 335 | 268× | .bind(owner) |
| 336 | 268× | .bind(repo_id) |
| 337 | 268× | .fetch_all(pool) |
| 338 | 268× | .await |
| 339 | 268× | } |
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | 31× | pub async fn serving_owner(pool: &Pool, owner: &str) -> sqlx::Result<Vec<Runner>> { |
| 344 | 31× | sqlx::query_as("SELECT * FROM flow_runners WHERE (scope_owner = '' AND scope_repo_id IS NULL) OR scope_owner = $1 ORDER BY name") |
| 345 | 31× | .bind(owner) |
| 346 | 31× | .fetch_all(pool) |
| 347 | 31× | .await |
| 348 | 31× | } |
| 349 | |
|
| 350 | |
|
| 351 | 0× | pub async fn set_scope(pool: &Pool, id: i64, scope: &Scope) -> sqlx::Result<()> { |
| 352 | 0× | sqlx::query("UPDATE flow_runners SET scope_owner = $1, scope_repo_id = $2 WHERE id = $3") |
| 353 | 0× | .bind(&scope.owner) |
| 354 | 0× | .bind(scope.repo_id) |
| 355 | 0× | .bind(id) |
| 356 | 0× | .execute(pool) |
| 357 | 0× | .await?; |
| 358 | 0× | Ok(()) |
| 359 | 0× | } |
| 360 | |
|
| 361 | |
|
| 362 | 17× | pub async fn pending_registrations(pool: &Pool) -> sqlx::Result<Vec<(String, i64, i64)>> { |
| 363 | 17× | sqlx::query_as("SELECT created_by, created_ms, expires_ms FROM flow_runner_registrations WHERE used_ms IS NULL AND expires_ms > $1 ORDER BY created_ms DESC") |
| 364 | 17× | .bind(now_ms()) |
| 365 | 17× | .fetch_all(pool) |
| 366 | 17× | .await |
| 367 | 17× | } |
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | | #[allow(clippy::too_many_arguments)] |
| 372 | 18× | pub async fn register( |
| 373 | 18× | pool: &Pool, |
| 374 | 18× | registration: &str, |
| 375 | 18× | name: &str, |
| 376 | 18× | token_hash: &str, |
| 377 | 18× | key: &str, |
| 378 | 18× | key_name: &str, |
| 379 | 18× | by_default: &str, |
| 380 | 18× | ) -> sqlx::Result<Option<Runner>> { |
| 381 | 18× | let mut tx = super::begin_write(pool).await?; |
| 382 | 18× | let now = now_ms(); |
| 383 | 18× | let found: Option<(String, String, Option<i64>)> = sqlx::query_as( |
| 384 | 18× | "SELECT created_by, scope_owner, scope_repo_id FROM flow_runner_registrations WHERE token_hash = $1 AND used_ms IS NULL AND expires_ms > $2", |
| 385 | 18× | ) |
| 386 | 18× | .bind(registration) |
| 387 | 18× | .bind(now) |
| 388 | 18× | .fetch_optional(&mut *tx) |
| 389 | 18× | .await?; |
| 390 | 18× | let Some((who, scope_owner, scope_repo_id)) = found else { return Ok(None) }; |
| 391 | 17× | let id: i64 = sqlx::query_scalar( |
| 392 | 17× | "INSERT INTO flow_runners (name, token_hash, source, key, key_name, created_ms, created_by, scope_owner, scope_repo_id) VALUES ($1, $2, 'registered', $3, $4, $5, $6, $7, $8) RETURNING id", |
| 393 | | ) |
| 394 | 17× | .bind(name) |
| 395 | 17× | .bind(token_hash) |
| 396 | 17× | .bind(key) |
| 397 | 17× | .bind(key_name) |
| 398 | 17× | .bind(now) |
| 399 | 17× | .bind(if who.is_empty() { by_default } else { &who }) |
| 400 | 17× | .bind(scope_owner) |
| 401 | 17× | .bind(scope_repo_id) |
| 402 | 17× | .fetch_one(&mut *tx) |
| 403 | 17× | .await?; |
| 404 | 17× | sqlx::query("UPDATE flow_runner_registrations SET used_ms = $1, runner_id = $2 WHERE token_hash = $3") |
| 405 | 17× | .bind(now) |
| 406 | 17× | .bind(id) |
| 407 | 17× | .bind(registration) |
| 408 | 17× | .execute(&mut *tx) |
| 409 | 17× | .await?; |
| 410 | 17× | tx.commit().await?; |
| 411 | 17× | get(pool, id).await |
| 412 | 18× | } |
| 413 | |
|
| 414 | |
|
| 415 | | #[derive(Clone, Debug, FromRow)] |
| 416 | | pub struct RunnerJob { |
| 417 | | pub owner: String, |
| 418 | | pub repo: String, |
| 419 | | pub run_number: i64, |
| 420 | | pub job: String, |
| 421 | | pub status: String, |
| 422 | | pub started_ms: Option<i64>, |
| 423 | | pub finished_ms: Option<i64>, |
| 424 | | pub receipt_attest: String, |
| 425 | | } |
| 426 | |
|
| 427 | |
|
| 428 | 4× | pub async fn history(pool: &Pool, id: i64, limit: i64, before: Option<i64>) -> sqlx::Result<Vec<RunnerJob>> { |
| 429 | 4× | sqlx::query_as( |
| 430 | 4× | "SELECT p.owner AS owner, p.name AS repo, r.number AS run_number, j.name AS job, j.status AS status, j.started_ms AS started_ms, \ |
| 431 | 4× | j.finished_ms AS finished_ms, j.receipt_attest AS receipt_attest \ |
| 432 | 4× | FROM flow_jobs j JOIN flow_runs r ON r.id = j.run_id JOIN repositories p ON p.id = r.repo_id \ |
| 433 | 4× | WHERE j.runner_id = $1 AND ($2 IS NULL OR j.started_ms < $3) ORDER BY j.started_ms DESC LIMIT $4", |
| 434 | 4× | ) |
| 435 | 4× | .bind(id) |
| 436 | 4× | .bind(before) |
| 437 | 4× | .bind(before) |
| 438 | 4× | .bind(limit) |
| 439 | 4× | .fetch_all(pool) |
| 440 | 4× | .await |
| 441 | 4× | } |
| 442 | |
|
| 443 | |
|
| 444 | 3× | pub async fn totals(pool: &Pool, id: i64) -> sqlx::Result<(i64, i64, i64)> { |
| 445 | 3× | sqlx::query_as( |
| 446 | 3× | "SELECT COUNT(*), COALESCE(SUM(CASE WHEN status = 'passed' THEN 1 ELSE 0 END), 0), CAST(COALESCE(SUM(finished_ms - started_ms), 0) AS BIGINT) \ |
| 447 | 3× | FROM flow_jobs WHERE runner_id = $1 AND finished_ms IS NOT NULL", |
| 448 | 3× | ) |
| 449 | 3× | .bind(id) |
| 450 | 3× | .fetch_one(pool) |
| 451 | 3× | .await |
| 452 | 3× | } |
| 453 | |
|
| 454 | |
|
| 455 | 255× | pub async fn running(pool: &Pool) -> sqlx::Result<Vec<(i64, i64)>> { |
| 456 | 255× | sqlx::query_as("SELECT runner_id, COUNT(*) FROM flow_jobs WHERE status = 'running' AND runner_id IS NOT NULL GROUP BY runner_id") |
| 457 | 255× | .fetch_all(pool) |
| 458 | 255× | .await |
| 459 | 255× | } |
| 460 | |
|
| 461 | 159× | pub async fn set_job_runner(pool: &Pool, job_id: i64, runner_id: i64) -> sqlx::Result<()> { |
| 462 | 159× | sqlx::query("UPDATE flow_jobs SET runner_id = $1 WHERE id = $2").bind(runner_id).bind(job_id).execute(pool).await?; |
| 463 | 159× | Ok(()) |
| 464 | 159× | } |