Running Your First Workflow
Now that you've created your first WfSpec
, let's explore the different ways to run it. LittleHorse provides multiple methods to execute workflows, each suited for different use cases.
This tutorial assumes you have completed the Your First WfSpec
guide.
Running with lhctl
The simplest way to run a workflow is using the command-line interface. The lhctl
command provides a quick way to execute and monitor workflows:
# Run the workflow with a name parameter
lhctl run getting-started name Obi-Wan
You'll see output like:
{
"id": {
"id": "69881bf9aaf84c2f84bdde7ceb2dd105"
},
"wfSpecId": {
"name": "getting-started",
"majorVersion": 0,
"revision": 0
},
"oldWfSpecVersions": [],
"status": "RUNNING",
"greatestThreadrunNumber": 0,
"startTime": "2024-12-17T01:53:47.212Z",
"threadRuns": [
{
"wfSpecId": {
"name": "getting-started",
"majorVersion": 0,
"revision": 0
},
"number": 0,
"status": "RUNNING",
"threadSpecName": "entrypoint",
"startTime": "2024-12-17T01:53:47.296Z",
"childThreadIds": [],
"haltReasons": [],
"currentNodePosition": 1,
"handledFailedChildren": [],
"type": "ENTRYPOINT"
}
],
"pendingInterrupts": [],
"pendingFailures": []
}
The lhctl
command is perfect for development and testing scenarios. It's also commonly used in CI/CD pipelines for automation.
Running from the Dashboard
LittleHorse provides a visual interface for running and monitoring workflows:
- Navigate to
http://localhost:8080
in your browser - Click on the "getting-started" workflow
- Click "Execute"
- Enter "Obi-Wan" in the name field
- Click "Execute Workflow"
The dashboard will show you the workflow's execution status in real-time, making it ideal for debugging.
Running with the Java SDK
For production applications, you'll typically want to run workflows programmatically. Create a new file called RunWorkflow.java
:
package io.littlehorse.tutorial;
import io.littlehorse.sdk.common.config.LHConfig;
import io.littlehorse.sdk.client.LHClient;
public class RunWorkflow {
public static void main(String[] args) throws Exception {
// Initialize the client
LHConfig config = new LHConfig();
LHClient client = new LHClient(config);
// Run the workflow
String wfRunId = client.runWorkflow(
"getting-started",
java.util.Map.of("name", "Anakin"),
null
).getId();
System.out.println("Started workflow with ID: " + wfRunId);
}
}
The Java SDK provides the most flexibility for running workflows. You can integrate it into your existing applications and handle workflow execution programmatically.
Choosing the Right Method
Each method has its ideal use case:
Method | Best For |
---|---|
lhctl | Development, testing, and CI/CD pipelines |
Dashboard | Debugging, monitoring, and team collaboration |
Java SDK | Production applications and system integration |
Remember, all methods interact with the same LittleHorse server, so you can mix and match them based on your needs.
Wrapping Up
You've learned how to run workflows using different methods and monitor their execution. In the next lesson, we'll dive deeper into debugging workflows and handling errors.
If you haven't already:
- Join the LittleHorse Slack Community
- Give us a star on GitHub
- Check out our documentation