cogk / reacteur

Automation and computation toolbox for no-code development for Frappe / Dodock.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feat: Continuations

cogk opened this issue · comments

Examples:

  • Prompt: Asking a value to the user is a continuation, because it is asynchronous
flowchart TB

subgraph flow1 [Subflow 1]
direction TB
Z1[Entrypoint]
-->A1(["A1. prompt (What is your name?)"])
-->|text| B1[\B1. Suspension/]
end

flow1 -.->|"Continuation data:<br>{'text': text, 'continuation_token': 'subflow-2'}"| flow2

subgraph flow2 [Subflow 2]
direction TB
Z2[Entrypoint]
-->A2[/A2. Continuation\]
-->|text| B2(["B2. send_email (Hello {{ text }})"])
--> C2...
end

Storing data across execution contexts

  • susp Suspension: The act of stopping a flow with the intent of continuing the execution at a later time. Suspension is the main mechanism allowing asynchronous tasks such as user interaction, docevent listening, scheduling.
  • coda Continuation data: A flow being suspended can store data to retrieve it at a later time. Continuation data is serialized and is safely persisted on disk. Continuation data MAY include data from the suspended flow, but only primitive values that can be serialized. Continuation data MUST include the id of the flow that should continue the execution.
  • cont Continuation: The act of resuming the execution of a flow by using persisted Continuation data.

How to store documents in Continuation Data?

It's not possible:

  1. because of the serialization constraints;
  2. because it does not make sense in an asynchronous context: the document might disappear or change before Continuation;

How to transfer complex data across execution contexts?

Let's say I have an interactive flow that mimics an authentication. It asks for the user's name and password, then the user's OTP code.

flowchart TB
subgraph main
    a[Entrypoint]
==>|init| b[Ask interactive: Username?]
-.->|ok\nasync| c[Ask interactive: Password?]
-.->|ok\nasync| z[Check user exists]
==>|ok| d[Ask interactive: OTP Code?]
-.->|ok\nasync| y[Check OTP]
==>|ok| e["Show result: Welcome {{ username }}!"]
end

subgraph context
%%subgraph coda1
bx([username]) --o b
%%subgraph coda2
cx([password]) --o c
%%subgraph coda3
dx([otp_code]) --o d
%%end
%%end
%%end
end

bx ~~~ cx ~~~ dx

bx --- z
cx --- z
bx --- y
dx --- y