createWorkflow()
function.
createWorkflow
serve()
method and exposed as a standalone route in your application.
However, when workflows are defined separately using serve()
, type safety is not guaranteed.
To ensure type safety for request and response when invoking other workflows, we introduced the createWorkflow()
function.
createWorkflow()
returns a referenceable workflow object that can be used in context.invoke()
.
context.invoke
, invoking workflow will wait until the invoked workflow finishes before running the next step.If you don’t want to wait for the invoked workflow, you can use context.call
instead of context.invoke
. Simply pass anotherWorkflow
in the example above to the workflow
parameter of context.call
.serveMany
comes in.
serveMany
createWorkflow()
does not expose your workflow like serve()
, it just initializes the workflow object.
To be able to use the workflow, they must be exposed with serveMany
function.
First step of using serveMany
is to define a catch-all route.
serveMany
in other frameworks, you can refer to the projects available in the examples
directory of the workflow-js repository.If you need any assistance, feel free to reach out through the chat box at the bottom right of this page.route.ts
file under a directory named with [...]
, like app/serve-many/[...any]/route.ts
serveMany
endpoint.If you pass a workflow object which is initialized with createWorkflow()
but not exposed inside the same serveMany
, you will get a runtime error.serveMany
. workflowOne
is a workflow that invokes workflowTwo
. To start workflowOne
, you can send a POST request to https://your-app/serve-many/workflow-one-route
.
workflow-one-route
is infered from the key passed to serveMany
. Similarly, you can send a POST request to https://your-app/serve-many/workflow-two-route
to start workflowTwo
.
serve
, you can pass options to both createWorkflow
and serveMany
. createWorkflow
accepts all the parameters that serve
does. serveMany
accepts some specific parameters.
createWorkflow
and serveMany
, the value specified in createWorkflow
will take precedence.
Additionally, when you invoke workflowOne
from another workflow, some options defined in createWorkflow
for workflowOne
will be applied in the invocation request. These options include retries
, failureFunction
, failureUrl
, and flowControl
.
invoke
is that you cannot create an infinite chain of workflow invocations. If you set up an ‘invoke loop’ where workflows continuously invoke other workflows, the process will fail once it reaches a depth of 100.