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

@ -114,11 +114,12 @@ defmodule Mv.Membership.Member do
if member.membership_fee_type_id && member.join_date do
if Application.get_env(:mv, :sql_sandbox, false) do
# Run synchronously in test environment for DB sandbox compatibility
# Use skip_lock?: true to avoid nested transactions (after_action runs within action transaction)
# Return notifications to Ash so they are sent after commit
case Mv.MembershipFees.CycleGenerator.generate_cycles_for_member(
member.id,
today: Date.utc_today(),
skip_lock?: false
skip_lock?: true
) do
{:ok, _cycles, notifications} ->
{:ok, member, notifications}
@ -134,8 +135,7 @@ defmodule Mv.Membership.Member do
end
else
# Run asynchronously in other environments
# Notifications cannot be returned in async case, so they will be lost
# This is acceptable as cycle generation is not critical for member creation
# Send notifications explicitly since they cannot be returned via after_action
Task.start(fn ->
case Mv.MembershipFees.CycleGenerator.generate_cycles_for_member(member.id) do
{:ok, _cycles, notifications} ->