new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Temporal · Concepts · all subjects

approval/multi-level

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Multi-level approval workflow pattern

The multi-level approval pattern loops through each required level (e.g., L1, L2, L3) and waits with a per-level timeout. The helper logic checks whether a Signal has arrived for the current level. If a timeout occurs at any level, the Workflow exits with a timeout result. If any level returns a rejection, the Workflow exits immediately without proceeding to subsequent levels.

MultiLevelApprovalData structure

The MultiLevelApprovalData type holds the following fields: level (string with values "L1", "L2", or "L3"), approver (string), decision (string), and comments (string). This data type extends the basic approval data with a level field that identifies which approval tier the decision belongs to.

Python multi-level approval workflow implementation

```python # models.py from dataclasses import dataclass @dataclass class MultiLevelApprovalData: level: str # "L1", "L2", "L3" approver: str decision: str comments: str # workflows.py import asyncio from datetime import timedelta from temporalio import workflow from models import MultiLevelApprovalData @workflow.defn class MultiLevelApprovalWorkflow: def __init__(self) -> None: self.approvals: list[MultiLevelApprovalData] = [] @workflow.run async def run(self, request_id: str, timeout_per_level_seconds: int) -> str: required_levels = ["L1", "L2", "L3"] timeout = timedelta(seconds=timeout_per_level_seconds) # Require approval at each level in sequence for level in required_levels: try: # Wait for a Signal carrying this level's approval await workflow.wait_condition( lambda lv=level: any(a.level == lv for a in self.approvals), timeout=timeout, ) except asyncio.TimeoutError: return f"Timeout at {level}" approval = next(a for a in self.approvals if a.level == level) # Stop the chain early if any level rejects if approval.decision == "REJECTED": return f"Rejected at {level} by {approval.approver}" return "Fully approved through all levels" # Signal handler: collect each level's approval as it arrives @workflow.signal def submit_approval(self, data: MultiLevelApprovalData) -> None: self.approvals.append(data) ``` This shows a multi-level approval Workflow in Python that waits for sequential approvals and exits early on rejection.

Go multi-level approval workflow implementation

```go // types.go type MultiLevelApprovalData struct { Level string // "L1", "L2", "L3" Approver string Decision string Comments string } // workflow.go func MultiLevelApprovalWorkflow(ctx workflow.Context, requestId string, timeoutPerLevel time.Duration) (string, error) { var approvals []MultiLevelApprovalData requiredLevels := []string{"L1", "L2", "L3"} // Collect every approval Signal as it arrives workflow.Go(ctx, func(ctx workflow.Context) { signalChan := workflow.GetSignalChannel(ctx, "submitApproval") for { var data MultiLevelApprovalData signalChan.Receive(ctx, &data) approvals = append(approvals, data) } }) // Require approval at each level in sequence for _, level := range requiredLevels { lv := level // Wait for a Signal carrying this level's approval ok, err := workflow.AwaitWithTimeout(ctx, timeoutPerLevel, func() bool { for _, a := range approvals { if a.Level == lv { return true } } return false }) if err != nil { return "", err } if !ok { return fmt.Sprintf("Timeout at %s", lv), nil } var approval MultiLevelApprovalData for _, a := range approvals { if a.Level == lv { approval = a break } } // Stop the chain early if any level rejects if approval.Decision == "REJECTED" { return fmt.Sprintf("Rejected at %s by %s", lv, approval.Approver), nil } } return "Fully approved through all levels", nil } ``` This shows a multi-level approval Workflow in Go that iterates through required levels and waits for each approval sequentially.

Java multi-level approval workflow implementation

```java // MultiLevelApprovalData.java public class MultiLevelApprovalData { private String level; // "L1", "L2", "L3" private String approver; private String decision; private String comments; } // MultiLevelApprovalWorkflowImpl.java public class MultiLevelApprovalWorkflowImpl implements ApprovalWorkflow { private List<MultiLevelApprovalData> approvals = new ArrayList<>(); private String[] requiredLevels = {"L1", "L2", "L3"}; @Override public String execute(String requestId, Duration timeoutPerLevel) { // Require approval at each level in sequence for (String level : requiredLevels) { // Wait for a Signal carrying this level's approval boolean received = Workflow.await( timeoutPerLevel, () -> hasApprovalForLevel(level)); if (!received) { return "Timeout at " + level; } MultiLevelApprovalData approval = getApprovalForLevel(level); // Stop the chain early if any level rejects if (approval.getDecision().equals("REJECTED")) { return "Rejected at " + level + " by " + approval.getApprover(); } } return "Fully approved through all levels"; } // Signal handler: collect each level's approval as it arrives @Override public void submitApproval(MultiLevelApprovalData data) { approvals.add(data); } private boolean hasApprovalForLevel(String level) { return approvals.stream().anyMatch(a -> a.getLevel().equals(level)); } private MultiLevelApprovalData getApprovalForLevel(String level) { return approvals.stream() .filter(a -> a.getLevel().equals(level)) .findFirst() .orElse(null); } } ``` This shows a multi-level approval Workflow in Java that collects approvals and processes them sequentially at each level.

TypeScript multi-level approval workflow implementation

```typescript // types.ts export interface MultiLevelApprovalData { level: 'L1' | 'L2' | 'L3'; approver: string; decision: string; comments: string; } // workflows.ts import * as wf from '@temporalio/workflow'; import { MultiLevelApprovalData } from './types'; export const submitApprovalSignal = wf.defineSignal<[MultiLevelApprovalData]>('submitApproval'); export async function multiLevelApprovalWorkflow( requestId: string, timeoutPerLevelMs: number, ): Promise<string> { const approvals: MultiLevelApprovalData[] = []; const requiredLevels = ['L1', 'L2', 'L3'] as const; // Signal handler: collect each level's approval as it arrives wf.setHandler(submitApprovalSignal, (data: MultiLevelApprovalData) => { approvals.push(data); }); // Require approval at each level in sequence for (const level of requiredLevels) { // Wait for a Signal carrying this level's approval const received = await wf.condition( () => approvals.some((a) => a.level === level), timeoutPerLevelMs, ); if (!received) { return `Timeout at ${level}`; } const approval = approvals.find((a) => a.level === level)!; // Stop the chain early if any level rejects if (approval.decision === 'REJECTED') { return `Rejected at ${level} by ${approval.approver}`; } } return 'Fully approved through all levels'; } ``` This shows a multi-level approval Workflow in TypeScript that iterates through required levels and waits for each with a per-level timeout.

Give your agent this brain