| 1 |
|
defmodule DaProductApp.Transactions.Watchdog do |
| 2 |
|
@moduledoc """ |
| 3 |
|
Periodic job to process scheduled follow-up requests (ChkTxn / Reversal) timeouts. |
| 4 |
|
""" |
| 5 |
|
use GenServer |
| 6 |
|
alias DaProductApp.Transactions.Service |
| 7 |
|
|
| 8 |
|
@interval_ms 5_000 |
| 9 |
|
|
| 10 |
1 |
def start_link(opts), do: GenServer.start_link(__MODULE__, opts, name: __MODULE__) |
| 11 |
|
|
| 12 |
|
@impl true |
| 13 |
|
def init(state) do |
| 14 |
1 |
schedule() |
| 15 |
|
{:ok, state} |
| 16 |
|
end |
| 17 |
|
|
| 18 |
|
@impl true |
| 19 |
|
def handle_info(:tick, state) do |
| 20 |
:-( |
Service.process_expired_followups() |
| 21 |
:-( |
schedule() |
| 22 |
|
{:noreply, state} |
| 23 |
|
end |
| 24 |
|
|
| 25 |
1 |
defp schedule, do: Process.send_after(self(), :tick, @interval_ms) |
| 26 |
|
end |