defmodule GitGud.Repo.Migrations.AddRunnerRequestRecovery do
use Ecto.Migration
@moduledoc """
Persists the (runner_id, request_key) -> workflow_job_id mapping
forgejo-runner sends an `x-runner-request-key` UUID with each
FetchTask. If the runner retries with the same key (network blip
dropping the response), we re-return the previously-claimed job
instead of claiming a fresh one and orphaning the original.
Mirrors Forgejo upstream's recovery path
(`routers/api/actions/runner/interceptor.go` — "allow Actions runner
to recover tasks lost during fetching from intermittent errors").
Rows are pruned by the stale-job reaper or a TTL sweep — we treat
anything older than ~5 minutes as expired.
"""
def change do
create table(:runner_request_recovery, primary_key: false) do
add :runner_id, references(:runners, on_delete: :delete_all), null: false
add :request_key, :string, null: false
add :workflow_job_id, references(:workflow_jobs, on_delete: :delete_all), null: false
add :expires_at, :utc_datetime, null: false
end
create unique_index(:runner_request_recovery, [:runner_id, :request_key])
create index(:runner_request_recovery, [:expires_at])
end
end
1.2 KiB · text
5af55d9