feat(workflow): add WorkflowListener with per-event helpers#32
Open
mpge wants to merge 1 commit intofeat/workflow-runnerfrom
Open
feat(workflow): add WorkflowListener with per-event helpers#32mpge wants to merge 1 commit intofeat/workflow-runnerfrom
mpge wants to merge 1 commit intofeat/workflow-runnerfrom
Conversation
Final piece of the workflow stack for Phoenix. Provides a thin wrapper
that bridges domain events into WorkflowRunner.run_for_event/2.
Each helper maps an event to a canonical workflow trigger name
(matching the 12-event set in WorkflowEngine.trigger_events/0) and
fires the runner in a supervised Task so a slow workflow never blocks
the mutation that fired it.
Phoenix doesn't auto-emit ApplicationEvents the way Spring or
EventEmitter2 do, so host apps opt in by calling these helpers from
their TicketService wrappers or post-write PubSub / Oban handlers:
# After creating a ticket:
WorkflowListener.ticket_created(ticket)
# After a reply:
WorkflowListener.reply_created(reply)
Runner failures are caught inside the spawned task and Logger.error-ed;
they never propagate back to the caller.
With this commit the chain is complete end-to-end for Phoenix:
TicketService mutation → WorkflowListener.<event>(ticket) →
Task / Task.Supervisor → WorkflowRunner.run_for_event →
WorkflowEngine (conditions) + WorkflowExecutor (actions) →
workflow_logs row
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Final piece of the workflow stack for Phoenix. Provides a thin wrapper (
WorkflowListener) that bridges domain events intoWorkflowRunner.run_for_event/2.Each helper maps an event to a canonical workflow trigger name (matching the 12-event set in
WorkflowEngine.trigger_events/0) and fires the runner in a supervisedTaskso a slow workflow never blocks the mutation that fired it.Opt-in wire-up
Phoenix doesn't auto-emit ApplicationEvents the way Spring or EventEmitter2 do, so host apps opt in by calling these helpers from their
TicketServicewrappers or post-write PubSub / Oban handlers:Per-event helpers
ticket_created/1,ticket_updated/1,ticket_status_changed/1,ticket_priority_changed/1,ticket_assigned/1,ticket_reopened/1,ticket_tagged/1,ticket_department_changed/1,reply_created/1,sla_breached/1,sla_warning/1.Failure semantics
Runner failures are caught inside the spawned task and emitted via
Logger.error/1. They never propagate back to the caller — matches the "one bad workflow never blocks the mutation" rule applied everywhere else in this stack.Complete chain
Dependencies
feat/workflow-runner), which is stacked on feat(workflow): add WorkflowExecutor for action dispatch #30 (feat/workflow-executor).Test plan
fire/2argument validation,reply_created/1shape handling, and interface checks for every per-event helper