Persistent, multi-node-safe implementation of the
Shopifex.RedirectAfterAgent behaviour, backed by a database table instead of
an in-memory Agent.
Use this (not the default in-memory Shopifex.RedirectAfterAgent) whenever the
app runs on more than one node. Shopify's /payment/complete redirect is a
fresh top-level navigation with no session affinity, so behind a load balancer
(Fly.io, multiple k8s pods, …) it can land on a different node than the one
that ran select_plan. A node-local cache misses there and the Grant is
silently dropped; a shared table does not.
Setup
Configure it as the redirect-after store:
config :shopifex, :redirect_after_agent, Shopifex.RedirectAfter.Ecto(
mix shopifex.installgenerates this line and the migration below for new apps.) There is no process to add to your supervision tree — unlike the in-memory agent, this module is stateless and talks toShopifex.Shops.repo()directly.Add a migration for the backing table:
defmodule MyApp.Repo.Migrations.CreateShopifexChargeRedirects do use Ecto.Migration def change do create table(:shopifex_charge_redirects, primary_key: false) do add :charge_id, :bigint, primary_key: true add :redirect_after, :text, null: false add :inserted_at, :utc_datetime, null: false end end end
Semantics
Matches Shopifex.RedirectAfterAgent exactly:
set/2upsertscharge_id -> redirect_after. A binary charge id is coerced to an integer withInteger.parse/1(treating non-integers as a no-op:ok).get/1is one-shot: it deletes the row and returns itsredirect_after, ornilif there is no entry (treating non-integer binary ids asnil).