operations tier

operations-triggers

Event-driven trigger system for automating workflows

Event-driven trigger system for automating workflows

Tieroperations
Roleunclassified (baselined)
Pathcrates/operations/triggers
Edition2021
Targetsoperations_triggers
Public items0 across 0 modules
Tests40

What it is for

operations-triggers: Event-driven trigger system for automating workflows

Overview

This crate provides a trigger system that reacts to domain events and executes configured actions. It enables automation like "when an appointment is created, send a confirmation email" or "when an order is cancelled, initiate refund processing".

Layer

Operations - depends on: foundation-basemodels

Key Types

Example

use operations_triggers::{TriggerService, CreateTriggerRequest};
use serde_json::json;

let service = TriggerService::from_pool(pool);

// Create a trigger: "When appointment created, send notification"
let (trigger, event) = service.create_trigger(CreateTriggerRequest {
tenant_id: Some(tenant_id),
name: "appointment-confirmation".to_string(),
description: Some("Send confirmation when appointment created".to_string()),
event_type: "appointment.created".to_string(),
condition: Some(json!({"status": "confirmed"})),
action_type: "send_notification".to_string(),
action_config: json!({
"channel": "email",
"template": "appointment_confirmation"
}),
retry_policy: None,
timeout_seconds: None,
priority: None,
}).await?;

// Later, when an event occurs:
let event_data = json!({
"appointment_id": "123",
"status": "confirmed",
"customer_id": "456"
});

// Evaluate triggers for this event
let executions = service.evaluate_event(
"appointment.created",
event_data,
Some(tenant_id),
None,
).await?;

// Process each matching trigger
for (execution, trigger) in executions {
// Mark as running
service.mark_execution_running(execution.id).await?;

// Execute the action (application-specific)
match execute_action(&trigger, &execution).await {
Ok(result) => {
service.mark_execution_success(execution.id, Some(result)).await?;
}
Err(e) => {
service.mark_execution_failed(execution.id, e.to_string()).await?;
}
}
}

Condition Evaluation

Triggers can have optional JSON conditions that filter which events activate them:

use operations_triggers::evaluate_condition;
use serde_json::json;

// Exact match
let condition = json!({"status": "confirmed"});
let event = json!({"status": "confirmed", "amount": 100});
assert!(evaluate_condition(&condition, &event));

// With operators
let condition = json!({"amount": {"$gt": 50}});
assert!(evaluate_condition(&condition, &json!({"amount": 100})));

// Multiple conditions with $and
let condition = json!({
"$and": 
{"status": "confirmed"},
{"amount": {"$gt": 100}}

});

Action Types

Built-in action types (application executes these):

TypeDescription
send_notificationCreate notification via domain-notifications
create_jobQueue background job via infrastructure-jobs
emit_eventEmit another event (for chaining)
http_webhookPOST to external URL
logLog the event (for debugging)

Capabilities

No public items.

How to use it

From this crate's own rustdoc:


## Condition Evaluation

Triggers can have optional JSON conditions that filter which events activate them:

Module structure

No public modules: the crate root is its whole surface.

Public surface

No public items.

Re-exports. Exported here, defined elsewhere.

ExportDefined in
TriggerRepositoryrepository::TriggerRepository
TriggerServiceservice::TriggerService
evaluate_conditionevaluator::evaluate_condition

Boundary

Reaches into foundation.

Shares tier operations with 40 other crates: operations-approval-workflow, operations-assessments, operations-block-imaging, operations-boot-media, operations-browser-agent-worker, operations-camera-discovery, operations-camera-liveview, operations-camera-registry, … (40 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)operations
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/operations/triggers
Vocabulary in force (lexicon)current

Tier flow. Which tiers this crate's own edges cross.

flowchart LR
  n_operations["operations"] --> n_foundation["foundation"]

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`foundation-basemodels`foundationnoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
chrono^0.4serdenoalways
regex^1noalways
serde^1derivenoalways
serde_json^1noalways
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonnoalways
thiserror^2noalways
tokio^1fullnoalways
uuid^1v4, serdenoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio^1full, test-utilnoalways

Build. None.

Depended on by. 1 workspace crate.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_triggers["application-triggers"] -->|uses| SELF
  SELF["operations-triggers"]
  SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
liboperations_triggers`src/lib.rs`

Error model

No public error type was detected: no public item declares a type named *Error, and no public signature returns one.

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimeyes
database accessyes
network I/Onone detected
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

1 workspace crate depends on this one: application-triggers.

Verification

KindCount
Unit tests40
Integration tests0
Examples0
Doctests1

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc00
Public modules with a //! block00

Metrics

MetricValue
Rust source files7
Source lines2345
Code lines1747
Public API items0
Public modules0
Tests40
Examples0
Cargo features0
Direct runtime dependencies10
Workspace reverse dependencies1
pie showData
    title Rust source composition
    "Code" : 1747
    "Blank or comment" : 598

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

All operations · Manual