runners: match jobs against declared labels too (labels ∪ agent_labels)
b90b1fc · gmorell · 2026-06-26 00:15
Message
{commit_body(@commit)}
Files changed
modified
lib/git_gud/workflows.ex
+18
−7
@@ -323,17 +323,28 @@ defmodule GitGud.Workflows do
| 323 | 323 | cheap and correct. |
| 324 | 324 | """ |
| 325 | 325 | def claim_next_job(%Runner{} = runner) do |
| 326 | − case runner do | |
| 327 | − %Runner{labels: %{"labels" => labels}} when is_list(labels) -> | |
| 328 | − do_claim_next_job(runner, labels) | |
| 329 | − | |
| 330 | − _ -> | |
| 331 | − nil | |
| 326 | + case effective_labels(runner) do | |
| 327 | + [] -> nil | |
| 328 | + labels -> do_claim_next_job(runner, labels) | |
| 332 | 329 | end |
| 333 | 330 | end |
| 334 | 331 | |
| 335 | 332 | def claim_next_job(_runner), do: nil |
| 336 | 333 | |
| 334 | + # Labels used for job matching = the operator-assigned `labels` UNION | |
| 335 | + # the runner-declared `agent_labels`. Without the union, a label added | |
| 336 | + # to the runner's config only lands in `agent_labels` (via Declare on | |
| 337 | + # restart) and never matches — you'd have to fully re-register. The | |
| 338 | + # union makes "edit config + restart" take effect as operators expect. | |
| 339 | + defp effective_labels(%Runner{labels: l, agent_labels: a}) do | |
| 340 | + Enum.uniq(label_list(l) ++ label_list(a)) | |
| 341 | + end | |
| 342 | + | |
| 343 | + defp effective_labels(_), do: [] | |
| 344 | + | |
| 345 | + defp label_list(%{"labels" => ls}) when is_list(ls), do: ls | |
| 346 | + defp label_list(_), do: [] | |
| 347 | + | |
| 337 | 348 | @doc """ |
| 338 | 349 | Claim up to `n` jobs in one batch — for runners that advertise |
| 339 | 350 | `task_capacity > 1` in their FetchTaskRequest. Returns a (possibly |
@@ -387,7 +398,7 @@ defmodule GitGud.Workflows do
| 387 | 398 | def claim_job_by_handle(runner, _), do: claim_next_job(runner) |
| 388 | 399 | |
| 389 | 400 | defp do_claim_specific_job(%Runner{id: rid} = runner, job_id) do |
| 390 | − %Runner{labels: %{"labels" => labels}} = runner | |
| 401 | + labels = effective_labels(runner) | |
| 391 | 402 | match_labels = if "self-hosted" in labels, do: labels, else: ["self-hosted" | labels] |
| 392 | 403 | |
| 393 | 404 | Repo.transaction(fn -> |
Parents: 10b7f9d