WEBVTT

00:00:00.500 --> 00:00:03.937
A client starts a job by calling start with a workflow kind

00:00:03.950 --> 00:00:04.888
and its arguments.

00:00:05.788 --> 00:00:09.265
The job may take many steps across several canisters, so the

00:00:09.278 --> 00:00:10.905
endpoint does not wait for it.

00:00:11.804 --> 00:00:15.176
It records the request and returns a receipt number, or a typed

00:00:15.189 --> 00:00:16.778
problem if it cannot accept.

00:00:17.676 --> 00:00:21.244
Admissions is ordinary application code like the Shop's Inventory.

00:00:22.142 --> 00:00:25.137
It checks the caller and the arguments, and it refuses with

00:00:25.150 --> 00:00:27.416
Busy when too many requests are waiting.

00:00:28.314 --> 00:00:30.944
All of this happens before the request is saved.

00:00:31.843 --> 00:00:34.304
The client can ask for the status of its receipt.

00:00:35.202 --> 00:00:36.569
At first it is Pending.

00:00:37.468 --> 00:00:40.957
Shortly after, the app takes the next request in line and starts

00:00:40.970 --> 00:00:41.934
it as a workflow.

00:00:42.832 --> 00:00:46.465
The status becomes Started and names the workflow and its execution

00:00:46.478 --> 00:00:46.934
number.

00:00:49.067 --> 00:00:51.072
Each workflow has its own folder.

00:00:51.972 --> 00:00:55.032
The graph file says which steps run and in what order.

00:00:55.931 --> 00:00:58.769
The memory version declares the data a job carries.

00:00:59.668 --> 00:01:02.806
Rules are small pure functions the graph refers to.

00:01:03.704 --> 00:01:05.944
Operations are the steps that do something.

00:01:06.842 --> 00:01:08.795
The local graph has three states.

00:01:09.694 --> 00:01:13.326
Open is a local step handled by ops dot open, and it leads to

00:01:13.339 --> 00:01:13.899
Audit.

00:01:14.798 --> 00:01:18.977
Audit is handled by ops dot audit and leads to Done, which succeeds.

00:01:19.876 --> 00:01:22.767
The order of work lives in this file and nowhere in the Rust

00:01:22.780 --> 00:01:23.287
code.

00:01:24.186 --> 00:01:26.764
The graph also declares what happens on failure.

00:01:27.662 --> 00:01:31.517
A step is retried when the retryable rule says so, up to five

00:01:31.530 --> 00:01:35.214
times with a growing delay, and the job pauses if retries run

00:01:35.227 --> 00:01:35.605
out.

00:01:36.504 --> 00:01:38.782
The rule itself is one line of Rust.

00:01:39.681 --> 00:01:42.402
Only the Unavailable error is worth retrying.

00:01:43.300 --> 00:01:46.920
A job's data is saved between steps, so it is declared in a

00:01:46.933 --> 00:01:49.524
versioned memory file like any other saved data.

00:01:50.423 --> 00:01:53.964
Progress lists the stages a job can be in, and here there is

00:01:53.977 --> 00:01:55.110
one, Request.

00:01:56.009 --> 00:01:57.871
It derives Takt's Progress.

00:01:58.769 --> 00:02:01.933
The file also declares the job's error type and how large a

00:02:01.946 --> 00:02:05.423
payload counts as, and those size answers must be truthful.

00:02:06.321 --> 00:02:09.668
Takt generates a trait from the graph with one method per handler.

00:02:10.566 --> 00:02:11.738
The app implements it.

00:02:12.636 --> 00:02:15.852
Open and audit each dispatch a ledger command, the one from

00:02:15.865 --> 00:02:16.764
the last lesson.

00:02:17.662 --> 00:02:20.618
On success the step adds the block number to the job's data

00:02:20.631 --> 00:02:22.558
and returns it as the next stage.

00:02:23.457 --> 00:02:26.035
On failure it returns one of the job's errors.

00:02:26.933 --> 00:02:29.147
Two lines connect the graph to the build.

00:02:30.045 --> 00:02:32.233
The build script lists the graph file.

00:02:33.131 --> 00:02:36.504
The workflow's mod dot r s includes the generated code.

00:02:37.402 --> 00:02:40.905
If the graph names a handler or a stage that the Rust code lacks,

00:02:41.087 --> 00:02:44.407
the build fails, and Takt's project check points at the line

00:02:44.420 --> 00:02:45.501
in the graph file.

00:02:47.633 --> 00:02:48.856
Now the job runs.

00:02:49.757 --> 00:02:52.830
Open dispatches its command and the ledger records a block.

00:02:53.728 --> 00:02:57.244
The job moves to Audit, which records a second block, and then

00:02:57.257 --> 00:02:57.817
to Done.

00:02:58.715 --> 00:03:01.931
The workflow test runs this graph and counts two commands and

00:03:01.945 --> 00:03:03.819
two block numbers in the finished job.

00:03:04.718 --> 00:03:07.973
The sequence workflow starts with a step of a different type.

00:03:08.872 --> 00:03:10.148
Reserve is Remote.

00:03:11.046 --> 00:03:12.687
It runs on a peer canister.

00:03:13.585 --> 00:03:16.931
The graph names an operation for it and a contract, and it catches

00:03:16.945 --> 00:03:19.848
a rejection and routes the job to a Rejected state.

00:03:20.747 --> 00:03:23.559
Prepare builds the dated ledger command for the peer's work

00:03:23.572 --> 00:03:24.666
dot dispatch route.

00:03:25.564 --> 00:03:28.038
The operation declares that it is idempotent.

00:03:28.937 --> 00:03:32.622
A retry sends the same request, and the peer returns its existing

00:03:32.635 --> 00:03:35.109
receipt for that command within the replay window.

00:03:36.007 --> 00:03:38.989
The author must check that the peer offers that guarantee before

00:03:39.002 --> 00:03:41.020
declaring the step safe to retry.

00:03:41.918 --> 00:03:45.278
When the reply comes back, the operation sorts it into three

00:03:45.291 --> 00:03:46.046
outcomes.

00:03:46.945 --> 00:03:49.132
A block number means the step succeeded.

00:03:50.030 --> 00:03:53.286
A clear business error means it failed, and the graph's catch

00:03:53.299 --> 00:03:54.067
takes over.

00:03:54.965 --> 00:03:57.856
A reply the operation cannot read yields Unknown.

00:03:58.754 --> 00:04:01.866
That outcome stays unresolved until the app has evidence.

00:04:02.765 --> 00:04:06.189
On the peer, the same application code receives the request.

00:04:07.088 --> 00:04:10.773
A route is a named, typed entry for messages from other canisters.

00:04:11.671 --> 00:04:15.122
This one decodes a command, dispatches it to the ledger, and

00:04:15.135 --> 00:04:16.424
replies with the result.

00:04:17.322 --> 00:04:20.382
Only canisters the owner has added as peers are accepted.

00:04:22.533 --> 00:04:26.230
Heavy16 finishes its outstanding work before an upgrade.

00:04:27.131 --> 00:04:28.954
The root names a check callback.

00:04:29.852 --> 00:04:33.472
The check refuses the upgrade while any request is queued, any

00:04:33.485 --> 00:04:36.285
job is pending, or any message is in transit.

00:04:37.183 --> 00:04:39.449
The app finishes that work and tries again.

