feat(backend): add conditional action workflows#384
Merged
Conversation
|
@oderahub Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
Nice implementation, lgtm! |
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
Implements backend support for conditional, sequential action chaining (workflows) on triggers.
A trigger can now define
steps[]to execute multiple actions in order. Step N+1 only runs if step N succeeds (default), or based on per-steprunIfrules. Step results are passed forward in a workflow context that later steps can reference via templates.Design Decisions
steps[]embedded onTrigger— backwards compatible. A trigger with no steps runs through the existing single-action path unchanged.steps.length > 0selects the workflow path. Joi validation rejects ambiguous combinations (top-levelactionUrlplus non-emptysteps[]).runIfpresets —success(default),failure,always. Full expression conditions deferred to a follow-up.idincontext.steps, so templates resolve as{{steps.fetchUser.output.userId}}regardless of step order changes.runId(UUID or BullMQ job id) injected into webhook payloads so receivers can dedupe across retries. Resumable retries that skip already-completed steps are deferred to a follow-up.What Changed
Added
backend/src/services/workflow.service.jsexecuteWorkflow(trigger, eventPayload, options)walks steps in order{ runId, event, trigger, steps, stepOrder, lastResult }WorkflowExecutionErroron failure unlessworkflowConfig.continueOnErroris truebackend/src/services/actionExecutor.service.jsexecuteSingleAction(triggerLike, eventPayload, options)used by both single-action and workflow pathsworkflow: { runId, stepId, previousSteps, stepOrder, lastResult }in the signed payloadbackend/src/utils/templater.js{{steps.<id>.output.<field>}}eval, no arbitrary expressions; missing paths are left unchangeddocs/workflows.mdcontinueOnErrorsemantics, and a mocked benchmark scriptNew tests
backend/__tests__/workflow.service.test.js— sequential success, default-skip on failure, compensating step viarunIf: failure,continueOnError, template resolution, missing-template passthroughbackend/__tests__/trigger.workflow.test.js— schema validation, ambiguous-combo rejection on create and update, duplicate step ids, per-step IP whitelist validationbackend/__tests__/workflow.processor.test.js— batch-mode workflow dispatch through the processorUpdated
backend/src/models/trigger.model.jssteps[](with required regex-validatedid) andworkflowConfig.continueOnErroractionUrlbecomes optional whensteps[]is non-emptybackend/src/middleware/validation.middleware.jsactionUrl + steps[]combos on both create and updatebackend/src/controllers/trigger.controller.jsstep <id>:)updateTrigger$unsetsactionUrlwhen switching from single-action to workflowbackend/src/worker/processor.jsexecuteWorkfloworexecuteSingleActionbackend/src/worker/poller.jsbackend/src/worker/queue.jsworkflow-<triggerId>for easier observabilitybackend/src/routes/docs.routes.jsbackend/src/routes/trigger.routes.jsvalidateBody(triggerUpdate)now applied on update (was previously missing)Behavior
runIf: 'failure'enables compensating steps (e.g. send a Telegram alert if the primary webhook fails).runIf: 'always'runs the step regardless of prior outcome.workflowConfig.continueOnError: truesuppresses the terminal throw on a failed run, but later steps with defaultrunIf: 'success'still skip — they must opt in viaalwaysorfailureto run after a failure.runIdandstepId) in their signed payload so receivers can dedupe across BullMQ retries.Tests
main(Mongo connection, missingsupertest, jest-styledescribein legacy tests) and unrelated to workflow changesgit diff --checkcleanOut of Scope (Deliberate)
{{steps.fetchUser.output.status}} == 200)slackto the trigger action enum (existing scope, not workflow-related)A
WorkflowRunpersistence model was also considered and deliberately deferred to keep this PR small.Notes
This PR composes cleanly with prior reliability/security work:
Closes #273