Skip to main content

Events

This guide provides a comprehensive explanation of how Flamingock events function.

Introduction

Flamingock utilizes events to notify the main application about the current state of the Flamingock process, as well as the eventual outcome of its execution.

The event-handling approach differs significantly depending on the type of runner being used:

  • For Spring-based applications, Flamingock leverages the ApplicationEventPublisher, which is provided during the build process.
  • For standalone applications, Flamingock requires an explicit event handler to be defined at build time.

Flamingock offers event handling capabilities for both Pipelines and Stages.

Type of events

Flamingock emits three types of events:

  • Start Event: Emitted just before the execution of Changes begins, either at the Stage or Pipeline level, after successful validation of configuration and preconditions.
  • Success Event: Emitted when the execution of all Changes in a Stage or Pipeline completes successfully, with no unhandled errors, indicating that all operations finished as expected.
  • Failure Event: Emitted when an unhandled error occurs during the execution of a Change and the process cannot continue normally.
warning

The Success and Failure events are mutually exclusive, only one of them will be raised for a given execution.

Standalone basic example

In the Flamingock builder, you must configure the events you intend to use and implement the corresponding listeners.

Builder

    Flamingock.builder()
.setPipelineStartedListener(new PipelineStartedListener())
.setPipelineCompletedListener(new PipelineCompletedListener())
.setPipelineFailedListener(new PipelineFailedListener())
.setStageStartedListener(new StageStartedListener())
.setStageCompletedListener(new StageCompletedListener())
.setStageFailedListener(new StageFailedListener())
.build()
.run();

Listener

public class StageCompletedListener implements ApplicationListener<StageCompletedEvent> {

public static int executed = 0;
@Override
public void accept(StageCompletedEvent stageCompletedEvent) {
executed++;
}
}

Spring-based basic example

Beans

  @Bean
public PipelineStartedListener pipelineStartedListener() {
return new PipelineStartedListener();
}

@Bean
public PipelineCompletedListener pipelineCompletedListener() {
return new PipelineCompletedListener();
}

@Bean
public PipelineFailedListener pipelineFailedListener() {
return new PipelineFailedListener();
}

@Bean
public StageStartedListener stageStartedListener() {
return new StageStartedListener();
}

@Bean
public StageCompletedListener stageCompletedListener() {
return new StageCompletedListener();
}

@Bean
public StageFailedListener stageFailedListener() {
return new StageFailedListener();
}

Listener

public class StageCompletedListener implements ApplicationListener<SpringStageCompletedEvent> {

public static int executed = 0;
@Override
public void accept(SpringStageCompletedEvent springStageCompletedEvent) {
executed++;
}
}