Quickstart: Workflow
This quickstart showcases how to write applications containing stateful, long-running, reliable workflows using the Workflow API. Catalyst hosts the workflow execution engine and manages the workflow state, with the external application containing the workflow definition and business logic.
Prerequisites
Before you proceed, ensure you have the following prereqs installed.
- Python
- .NET
- JavaScript
- Java
Log in to Catalyst
Authenticate to Diagrid Catalyst using the following command:
diagrid login
Confirm your organization and user details are correct:
diagrid whoami
Deploy quickstart project
Create a project and bootstrap the necessary resources to begin developing locally with the Workflow API. This command:
✔️ Creates a new Catalyst project
✔️ Enables managed workflow for the proejct
✔️ Creates an App ID for the order workflow application
✔️ Clones a quickstart application to your machine
✔️ Scaffolds a dev config file to run the quickstart code with the necessary Catalyst connectivity info
- Python
- .NET
- Javascript
- Java
diagrid project quickstart --type workflow --language python
diagrid project quickstart --type workflow --language csharp
diagrid project quickstart --type workflow --language javascript
diagrid project quickstart --type workflow --language java
Run sample application
To run the quickstart code locally, you can use the diagrid dev start
command. This command:
- Launches the local quickstart code: Locates the code directory using the value specified for
workDir
and launches the code using the app command inputs - Injects environment variables: Configures the Dapr client to talk to Catalyst using the
order-workflow
App ID API token - Streams application logs: Displays connectivity logs along with real-time app feedback directly in the terminal to make API testing simple
For additional details on the Catalyst local development experience, read Develop Locally with Catalyst APIs.
- Python
- .NET
- JavaScript
- Java
Install python dependencies in a virtual environment.
This quickstart uses the venv module to create the virtual environment. Please feel free to adapt if you prefer to use conda, pipenv, or another alternative.
python -m venv venv
- MacOS
- Linux
- Windows
If you are using MacOS, start the virtual environment with the following command:
source venv/bin/activate
Don't forget to close your virtual environment with deactivate
when done with the quickstart
If you are using Linux, start the virtual environment with the following command:
source venv/bin/activate
Don't forget to close your virtual environment with deactivate
when done with the quickstart
If you are using PowerShell on Windows, start the virtual environment with the following command:
venv/Scripts/Activate.ps1
If you are using the Command Prompt on Windows, start the virtual environment with the following command:
venv/Scripts/activate.bat
If running in the Windows Command Prompt, don't forget to close your virtual environment with venv/Scripts/deactivate.bat
when done with the quickstart
Install the python app requirements:
pip install -r requirements.txt
Install .NET dependencies.
donet restore
Install node dependencies.
npm install
Install maven dependencies.
mvn clean install
Run the diagrid dev start command:
diagrid dev start
Interact with Workflow API
With the quickstart application running, it's time to test the Workflow API. Use the curl commands below or take advantage of the REST Client extension using Visual Studio Code with the test.rest
file in the root folder of the repo.
Upon successful execution of the three curl commands below, the order-workflow
logs should show three requests:
- A request to start the workflow execution
- A status request
- A final request for the completed workflow output
You can also use the Workflow viewer in the Catalyst web console to see the details for your completed workflow instance.
Start workflow
Open a new terminal and execute the following curl command to start a new workflow instance:
curl -i -X POST http://localhost:5001/workflow/start -H "Content-Type: application/json" -d '{"Name":"Car", "Quantity":2}'
This command will return the instance ID of the workflow that has been started. Save this result as an environment variable for future API calls.
export WORKFLOW_ID=<YOUR_WORKFLOW_INSTANCE_ID>
Get workflow status
Get the current workflow status using the workflow instance ID:
curl -i -X GET http://localhost:5001/workflow/status/$WORKFLOW_ID
You can also see more detailed workflow logs using the Diagrid CLI:
diagrid workflow get $WORKFLOW_ID --app-id order-workflow
Clean up resources
If you are not going to continue to use this application, you can delete the resources using the following commands:
diagrid appid delete order-workflow
If you want to delete the entire Catalyst project, including the managed infrastructure resources, run the diagrid project delete
command.