The smallest workflow¶
A WhippleScript program is a workflow. A workflow is a durable process. It reacts to typed data until it gets to a result. This chapter shows the smallest complete workflow. It shows how to run the workflow and how to look in a run. Each subsequent chapter builds on the few lines that this chapter introduces.
Read this orientation before the first line of code. WhippleScript is a
Gleam-inspired syntax on a durable, stream-backed rule engine. It
deliberately has no arbitrary control flow. There is no for loop, no while,
and no exceptions. If you look for these constructs, the answer always has the
same shape. To branch, use case and pattern matching (chapter 7). To fan out,
let a rule fire one time for each matched fact (chapter 4). To make a sequence,
use a then chain (chapter 9). This limit is not an absent feature. This limit
lets the compiler check your orchestration and lets the runtime replay the
orchestration. The invariants of the compiler are the product.
The program¶
workflow Hello
output result Done
class Done {
message string
}
rule begin
when started
=> {
complete result {
message "hello"
}
}
Read the program from the top to the bottom:
- The
workflow Helloline gives the name of the program. When you start the program, whip makes an instance. An instance is a durable run. An instance has its own record of each event. - The
output result Doneline declares the data that a run supplies after success. The data is a value with the nameresult. The classDonegives its shape. - The
class Done { message string }line declares that shape. The class has one field with the namemessage. The field holds a string. The next chapter gives the full data on classes. If no other part of the program uses the shape, you can put the two lines together. The lineoutput result { message string }declares the class in position. - The
rule begin … => { … }block is a rule. A rule is the unit that reacts and acts. This rule reacts tostarted. Thestartedevent starts each instance. This rule then completes the workflow immediately. - The
complete result { message "hello" }statement ends the instance with success. The statement supplies the declared output.
Copy this shape each time that you start a new workflow. The applicable chapters give the full data on the parts. Chapter 2 gives the data on classes. Chapter 4 gives the data on rules. The skeleton is always the same: a workflow, its output contract, and a minimum of one rule that gets to an end.
How to run the program¶
Save the program as hello.whip. Then check the program:
The check command compiles the program and reports the problems. The command
runs no part of the program. A workflow that can never complete is an error.
Whip makes each workflow able to get to an end.
Now run the program:
The whip run command starts an instance. The command drives the instance
until no work stays. Whip keeps the run in a .whipplescript/ directory
adjacent to your program. The run contains each event and each item that the
instance knows. Thus the commands below can examine a run after the run
completes.
How to look in a run¶
Each instance keeps a full record. Two commands answer the largest part of the
questions. Each command takes the instance identifier that the run command
printed:
The status command shows the condition of the instance. It gives the
lifecycle state (running, completed, or failed), the terminal if the
instance got to one, and a summary of the pending work:
The log command gives the history of the events in sequence. For the program
above, the history has three lines: the start, one rule that fires, and the
completion:
#0001 … external.started source=external
#0002 … rule.committed source=kernel
#0003 … workflow.completed source=kernel
This check, run, and examine loop is the usual rhythm for each subject in this manual. When an example tells you to run the program and look at the log, use this loop.
Where next¶
Chapter 2 introduces the data model. It gives classes, the types of a field, and facts. A fact is a typed value that a workflow holds while the workflow runs. Chapter 2 also gives the command that examines the facts. A workflow can also fail deliberately with a declared error payload. Error handling has its own chapter, after this manual introduces effects.