Hey all!
I have a resource called Assignment
that’s backed by AshStateMachine and can go through several states: draft
→ assigned
→ closed
→ archived
.
When an assignment is closed
we need to perform a few side effects like triggering Notifiers or kicking off background jobs.
We’d like to allow users to archive
an assignment that’s in the assigned
state but we want to trigger all of the same side effects that happen when it gets closed (you can think of it like we want the assignment to go through the closed state before we archive it).
My initial thought was to add a before_action
change on the archive
action that checks the current state and conditionally calls the close
action on the resource.
Is that the best way to “chain” actions? Is there a better way to conditionally force an action/state transition to happen before another one?