Chapter 24: Temporal basics for the watcher

ConceptUse in the watcher
WorkflowOne watcher run
ActivityOne model call, one tool call, one alert post
SignalHuman approval
TimerApproval deadline
Retry policyRetry a failed model or tool call
QueryRead the current state

Determinism rule. Workflow code must give the same result on replay. Model calls, tool calls, database writes, and REST calls go in activities. Use Workflow.await, Workflow.sleep, and Workflow.currentTimeMillis() in the workflow. Do not use Thread.sleep or Instant.now() there.

Figure 24.1. The determinism rule as two questions. Thread.sleep and Instant.now() never appear in workflow code.
@WorkflowInterface
public interface WatcherWorkflow {
    @WorkflowMethod RunResult run(WatchRequest request);
    @SignalMethod void decideApproval(boolean approved);
    @QueryMethod String state();
}
Figure 24.2. Every concept in the table, in one run. The figure leaves out how the person's approval reaches the signal; in the exercise below, a REST call sends it.

Verify: Confirm the annotation packages and the starter configuration keys for SDK 1.35.0. Temporal’s Spring Boot starter starts the worker automatically when the app starts.

Exercise. Start a run through a REST endpoint. Read its state with a query. Approve a critical run. Confirm one alert posts.

docs