fix: address notification handling review feedback

1. Fix misleading comment in async create_member path
2. Use skip_lock?: true in test case for create_member
3. Fix generate_cycles_for_all_members/1
This commit is contained in:
Moritz 2025-12-15 16:20:37 +01:00
parent 4997493139
commit 40cdcbe453
Signed by: moritz
GPG key ID: 1020A035E5DD0824
2 changed files with 17 additions and 5 deletions

View file

@ -179,7 +179,19 @@ defmodule Mv.MembershipFees.CycleGenerator do
defp process_batch(batch, today) do
batch
|> Task.async_stream(fn member ->
{member.id, generate_cycles_for_member(member, today: today)}
case generate_cycles_for_member(member, today: today) do
{:ok, _cycles, notifications} = ok ->
# Send notifications for batch job
# This is a top-level job, so we need to send notifications explicitly
if Enum.any?(notifications) do
Ash.Notifier.notify(notifications)
end
{member.id, ok}
{:error, _reason} = err ->
{member.id, err}
end
end)
|> Enum.map(fn
{:ok, result} ->
@ -193,7 +205,7 @@ defmodule Mv.MembershipFees.CycleGenerator do
end
defp build_results_summary(results) do
success_count = Enum.count(results, fn {_id, result} -> match?({:ok, _}, result) end)
success_count = Enum.count(results, fn {_id, result} -> match?({:ok, _, _}, result) end)
failed_count = Enum.count(results, fn {_id, result} -> match?({:error, _}, result) end)
%{success: success_count, failed: failed_count, total: length(results)}