Trigger Rules
Trigger rules are a fundamental feature in Cloacina that determine when tasks should execute beyond simple dependency satisfaction. They provide a powerful way to implement complex workflow logic and conditional execution patterns.
Trigger rules are conditions that determine whether a task should execute after its dependencies are satisfied. They provide:
- Conditional task execution based on workflow state
- Complex decision-making logic
- Integration with workflow context
- Flexible composition of conditions
By default, tasks use the “Always” trigger rule, meaning they execute whenever their dependencies are satisfied. This is the simplest and most common case.
These rules evaluate the status of other tasks in the workflow:
TaskSuccess
: Execute when a specific task completes successfullyTaskFailed
: Execute when a specific task failsTaskSkipped
: Execute when a specific task is skipped
These rules evaluate values in the workflow context:
Equals
: Value matches exactlyNotEquals
: Value doesn’t matchGreaterThan
: Value is greater than expectedLessThan
: Value is less than expectedContains
: Value contains the expected valueNotContains
: Value doesn’t contain the expected valueExists
: Value exists in contextNotExists
: Value doesn’t exist in context
Rules can be combined using logical operators:
All
: All conditions must be trueAny
: Any condition can be trueNone
: No conditions should be true
For practical examples of combining different types of rules, see our Error Handling Tutorial which demonstrates:
- Combining task status rules for fallback behavior
- Using context values for conditional execution
- Complex rule composition patterns
-
Context Management
- Don’t use trigger rules as a substitute for proper task dependencies
- Avoid using context values that could be expressed as task dependencies
- Keep workflow structure clear and explicit
-
Rule Evolution
- Keep rules focused on business outcomes and workflow paths
- Document the business logic behind complex rules
- Consider how rules will evolve with business requirements
-
Rule Design
- Start with the default “Always” rule and add conditions only when necessary
- Use context values for dynamic decisions, keeping keys consistent
- Document expected context values and their impact on workflow paths
- Consider task dependencies carefully when using status-based rules
Trigger rules provide a flexible way to control task execution based on workflow state and context. By combining task status rules, context value rules, and logical operators, you can create sophisticated workflow patterns that adapt to your business needs. Remember to consider the operational aspects of rule design and maintenance to ensure your workflows remain clear and maintainable over time.