From ee6975bc39d012cb13545e23562180d2b6869f5e Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 31 Mar 2026 15:54:19 -0500 Subject: [PATCH] Fix ASOS upsert timeout: infinite tx timeout, bump prod pool to 20 458K-record upsert held a connection for the entire transaction, exceeding the 15s Postgrex timeout on prod. Set transaction timeout to infinity and increase prod pool from 10 to 20. --- config/runtime.exs | 2 +- lib/microwaveprop/propagation.ex | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 7ceef372..41193c66 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -49,7 +49,7 @@ if config_env() == :prod do config :microwaveprop, Microwaveprop.Repo, # ssl: true, url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "20"), # For machines with several cores, consider starting multiple pools of `pool_size` # pool_count: 4, socket_options: maybe_ipv6 diff --git a/lib/microwaveprop/propagation.ex b/lib/microwaveprop/propagation.ex index bcb0ae40..0cd4f162 100644 --- a/lib/microwaveprop/propagation.ex +++ b/lib/microwaveprop/propagation.ex @@ -77,19 +77,22 @@ defmodule Microwaveprop.Propagation do end) result = - Repo.transaction(fn -> - entries - |> Enum.chunk_every(500) - |> Enum.reduce(0, fn chunk, acc -> - {count, _} = - Repo.insert_all(GridScore, chunk, - on_conflict: {:replace, [:score, :factors, :updated_at]}, - conflict_target: [:lat, :lon, :valid_time, :band_mhz] - ) + Repo.transaction( + fn -> + entries + |> Enum.chunk_every(500) + |> Enum.reduce(0, fn chunk, acc -> + {count, _} = + Repo.insert_all(GridScore, chunk, + on_conflict: {:replace, [:score, :factors, :updated_at]}, + conflict_target: [:lat, :lon, :valid_time, :band_mhz] + ) - acc + count - end) - end) + acc + count + end) + end, + timeout: :infinity + ) case result do {:ok, _count} -> prune_old_scores()