top of page

Part 2 - LittleHorse Advanced Concept Series: Loops

Updated: Mar 15

Welcome back to our advanced concept blog series on IT Incident Management with LittleHorse! If you've been following along, you've already seen how conditionals can level up your workflows through different scenarios. Now, let's add another layer of sophistication with loops.

Loops let your workflow persistently do things until a condition changes. 

Imagine a diligent droid in a Star Wars saga, tirelessly working on a task until told otherwise.

That's what loops do in our incident management system.

Why do Loops matter?

In IT Incident Management, some tasks need repetition. Maybe we're waiting for an incident to resolve or continuously checking system health. 

Loops in LittleHorse let us automate these repetitive tasks efficiently, reducing manual oversight and speeding up resolution times.

Let's jump back into our `` file. We're adding a loop that'll keep an eye on incidents until they're marked as resolved. Here's a sneak peek into how we set it up:

Inside ConditionalsExample.define Workflow method

    wf.condition(incidentResolved, Comparator.EQUALS, false),
    loopBody -> {
        loopBody.execute(PERIODIC_CHECK_TASK, incidentDetails);
        loopBody.sleepSeconds(30); // Take a breather, then check again

This loop uses the doWhile construct to continuously execute the PERIODIC_CHECK_TASK as long as the incidentResolved variable is false. It's like saying, "Keep checking on this incident every 30 seconds until it's resolved.”

You might be wondering what’s the role of periodic check task in this example.

Remember the PERIODIC_CHECK_TASK we mentioned in Part 1? Here's where it shines. 

This task might involve checking logs, querying system status, or even sending out automated pings to see if an issue persists. And with our loop in place, it keeps running at regular intervals, automating what would otherwise be a tedious manual process.

Introducing serves as the central hub for initializing and managing our workflow. It's where all the pieces of our system come together. Here's a basic setup to get us started:

// Inside

public class App {

    public static void main(String[] args) {
        // Initialize workflow and task workers
        ConditionalsExample workflow = new ConditionalsExample();
        workflow.getWorkflow().registerWfSpec(new LHConfig().getBlockingStub());

        new LHTaskWorker(new IncidentWorker(), VERIFY_TASK, new LHConfig()).start();
        // Additional task workers will be started here

This code snippet initializes our workflow and starts a task worker for `VERIFY_TASK`.

Our workflow tasks, such as verifying incidents or sending alerts, are handled in individual Java files. Let's look at ``, which defines our task methods:

public class IncidentWorker {

    public String verifyIncident(String incidentDetails) {
        // Logic for verifying incident details

    // Additional task methods like periodic checks and sending alerts

`` contains task methods annotated with `@LHTaskMethod`, each dedicated to handling a specific part of our incident management process.

With `` orchestrating the workflow and `` handling specific tasks, our system is starting to take shape. We’ve got the core (``) directing the flow, the orchestrator (``) managing execution, and the executors (`` and others) performing tasks.

While we can't fully test the entire workflow yet, we’re laying down the framework for a comprehensive IT Incident Management system. We’re building towards a fully integrated workflow capable of dynamically responding to incidents with precision.

What's Ahead?

Next, we'll finalize our task files, refine, and explore integrating external events to further enhance our workflow's responsiveness and intelligence. Our goal is a robust system capable of managing IT incidents not just reactively, but proactively.

Stay tuned, and happy coding! In the meantime, keep exploring the endless possibilities that loops and conditionals open up in the realm of workflow automation. Imagine the efficiency, the time saved, and the potential for even more complex automation. The future is bright (and looped)!

9 views0 comments

Recent Posts

See All


bottom of page