Repository navigation
Add the ash_workflow.gen.acknowledgement recipe - #139
Conversation
2087214 to
9d4aad6
Compare
51d6018 to
1144974
Compare
… row `AshWorkflow.Changes.RecordEvent` no longer calls `AshWorkflow.Scheduler.notify_state_change/1` for a create whose record carries `upsert_action: :update` metadata. The row stays in the step it was in, so its deadlines are unchanged. The `[:ash_workflow, :transition]` span still emits `:stop` on that path. Its `:start` event fires in `change/3`, before the data layer reports whether the row was inserted, and skipping `:stop` would leave the span open.
A create action with `upsert_condition` returns the existing row with `upsert_skipped: true` metadata when the condition does not match and `return_skipped_upsert?` is set. That row carries no `upsert_action` metadata, so `AshWorkflow.Changes.RecordEvent` appended an `:initial` log row and called `AshWorkflow.Scheduler.notify_state_change/1` for it. Both are now skipped, the same as for an upsert that updated the row.
`AshWorkflow.Changes.RecordEvent` reads `upsert_action` metadata to tell an upsert that inserted a row from one that updated it. Ash 3.29.0 added that metadata to `Ash.DataLayer.Ets` and `Ash.DataLayer.Mnesia`. With an older Ash, every upsert on ETS still logs an `:initial` row. AshPostgres sets the metadata from 2.10.0 on PostgreSQL 17 and later, and from 2.13.1 on every PostgreSQL version. AshPostgres is not a runtime dependency, so `mix.exs` cannot raise that floor for users.
`AshWorkflowTest.Postgres.UpsertWorkflow` upserts on a unique `code` and logs to `AshWorkflowTest.Postgres.UpsertTransition`. Its tests check that a single upsert and a bulk upsert onto an existing row write no second `:initial` row. On ETS, `AshWorkflow.UpsertTest` checks that a bulk upsert of one existing and one new code logs only the new row and does not notify the scheduler for the existing one.
1144974 to
e1bce7e
Compare
|
Findings from generating 1. The generated resource ignores the subject's multitenancy and data-layer extensionsThe acknowledgement resource and its transition log had no Suggestion: copy the subject's 2. The transition log cannot be tenant-scoped
3. The generated policies forbid every readThe recipe adds Suggestion: generate a read policy, such as 4. The first policy needs a SAT solver the recipe does not addIn an app with no policies yet, compiling the generated resource raised Suggestion: add a SAT solver dependency through Igniter when the app has none, or name the requirement in the notice. 5. The recipe depends on #147, which no release contains
Suggestion: release #147 before or with this recipe. 6. A repeated request still records an AshEvents eventWith AshEvents, a 7.
|
# Conflicts: # CHANGELOG.md # lib/ash_workflow/changes/record_event.ex # mix.exs # test/mix/ash_workflow/recipe_test.exs # test/support/postgres/domain.ex
# Conflicts: # CHANGELOG.md # documentation/recipes/index.md # mix.exs # test/mix/ash_workflow/recipe_test.exs
mix ash_workflow.gen.acknowledgement, a request recipe with one row per person per subject. It generates<Subject>Acknowledgementwith an identity:unique_personon(subject_id, person_id). The subject gainshas_many :acknowledgementsand anacknowledged_by_actor?calculation. Options:--person(required),--overdue-after,--module,--domain,--transition-log.Recipe.create_policy/2gates the:requestcreate action on a generatedChecks.CanRequest, which denies everyone until the application fills it in.Recipe.belongs_to/4typessubject_idandperson_idafter the primary keys of the subject and the--personresource.Recipe.validate_interval/2rejects an--overdue-aftershorter than the default Oban scheduler's precision floor with an Igniter issue.documentation/design/acknowledgement-recipe.mdand the recipe page, and links thegen.acknowledgementrow in the recipes index.CHANGELOG.mdlists the task under Unreleased.AshWorkflow.Changes.RecordEventso an upsert onto an existing row logs no:initialtransition and skipsAshWorkflow.Scheduler.notify_state_change/1, and raises theashrequirement to~> 3.29. The:requestupsert relies on both.Opening requests:
Decisions
acknowledgeis authorised byrelates_to_actor_via(:person). The recipe generates no check module for it, because the person asked is the person who confirms in every application.:requestupserts on:unique_personwithupsert_fields []. Asking a person who already has a row returns that row unchanged, sorequest_many/3can be called with the whole list each time it grows. A test asserts that repeatedrequest_many/3calls log one:initialrow per person.request_many/3is a second code interface on:requestwithargs: [:subject_id]. A list of maps runsAsh.bulk_create/4. A generic action would have needed the subject's primary key type for itssubject_idargument.acknowledged_by_actor?, reading^actor(:id)and ending in|| false, so it returnsfalse, notnil, for an actor with no acknowledgement. A version taking aperson_idargument would need adoblock, whichAsh.Resource.Igniter.defines_calculation/3does not match on a second run.has_one :latest_acknowledgement.recipes.mdgives one to every request recipe, but here the latest row belongs to whichever person was asked last.requested_at, so a transition an application adds that loops back into:pendingdoes not move the deadline.No change to
Mix.AshWorkflow.Recipe.config/config.exsgains oneash_domainsline for the new fixture domain, whichAsh.Domain.Igniter.add_resource_reference/3needs in order to find it.