Skip to content

Commit 8506279

Browse files
authored
fix: update events listeners code snipsets (#112) (#115)
1 parent e04ac5c commit 8506279

1 file changed

Lines changed: 45 additions & 21 deletions

File tree

docs/flamingock-library-config/events.md

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ Flamingock emits three types of events:
3232
The Success and Failure events are mutually exclusive, only one of them will be raised for a given execution.
3333
:::
3434

35+
## Event Emission Order
36+
37+
Events are emitted in a specific order during the Flamingock execution process:
38+
39+
1. **PipelineStartedEvent**: Emitted at the beginning of the pipeline execution, after validation and lock acquisition.
40+
2. **StageStartedEvent**: Emitted for each stage before its execution begins.
41+
3. **StageCompletedEvent** or **StageFailedEvent**: Emitted when a stage finishes successfully or fails. Only one of these will be emitted per stage.
42+
4. **PipelineCompletedEvent** or **PipelineFailedEvent**: Emitted at the end of the pipeline execution. Only one of these will be emitted, indicating overall success or failure.
43+
44+
If a stage fails, both StageFailedEvent and PipelineFailedEvent will be emitted. If the pipeline completes successfully, PipelineCompletedEvent is emitted after all stages have completed.
45+
46+
## Event Scope
47+
48+
Flamingock supports events at two levels:
49+
50+
- **Pipeline Events**: Provide information about the entire migration process.
51+
- **Stage Events**: Provide granular information about individual stage executions.
52+
53+
This allows you to monitor both high-level progress and detailed stage-by-stage execution status.
54+
55+
## Event Data
56+
57+
Events provide access to relevant information about the execution state:
58+
59+
- **Started Events** (`PipelineStartedEvent`, `StageStartedEvent`): These events are simple markers with no additional data.
60+
- **Completed Events**:
61+
- `StageCompletedEvent`: Provides access to the execution result via `getResult()`, which returns a `StageExecutor.Output` object containing the stage summary with details like the number of applied changes.
62+
- `PipelineCompletedEvent`: A simple marker event with no additional data.
63+
- **Failed Events** (`StageFailedEvent`, `PipelineFailedEvent`): Provide access to the exception that caused the failure via `getException()`, allowing you to inspect the error details.
64+
3565
## Standalone basic example
3666

3767
In the Flamingock builder, you must configure the events you intend to use and implement the corresponding listeners.
@@ -72,28 +102,22 @@ In the Flamingock builder, you must configure the events you intend to use and i
72102
<Tabs groupId="languages">
73103
<TabItem value="java" label="Java" default>
74104
```java
75-
public class StageCompletedListener implements ApplicationListener<StageCompletedEvent> {
76-
77-
public static int executed = 0;
78-
@Override
79-
public void accept(StageCompletedEvent stageCompletedEvent) {
80-
executed++;
81-
}
105+
public class StageCompletedListener implements Consumer<IStageCompletedEvent> {
106+
@Override
107+
public void accept(IStageCompletedEvent event) {
108+
System.out.println("Stage execution completed with " + event.getResult().getSummary().getAppliedChangesCount() + " changes applied");
109+
}
110+
}
82111
}
83112
```
84113
</TabItem>
85114
<TabItem value="kotlin" label="Kotlin">
86115
```kotlin
87-
class StageCompletedListener : (StageCompletedEvent) -> Unit {
88-
89-
companion object {
90-
var executed = 0
91-
}
92-
93-
override fun invoke(stageCompletedEvent: StageCompletedEvent) {
94-
executed++
95-
}
96-
}
116+
class StageCompletedListener : (IStageCompletedEvent) -> Unit {
117+
override fun invoke(event: IStageCompletedEvent) {
118+
println("Stage execution completed with ${event.result.summary.appliedChangesCount} changes applied")
119+
}
120+
}
97121
```
98122
</TabItem>
99123
</Tabs>
@@ -154,7 +178,7 @@ class StageCompletedListener : (StageCompletedEvent) -> Unit {
154178
}
155179

156180
@Bean
157-
fun StageStartedListener(): StageStartedListener {
181+
fun stageStartedListener(): StageStartedListener {
158182
return StageStartedListener()
159183
}
160184

@@ -180,21 +204,21 @@ public class StageCompletedListener implements ApplicationListener<SpringStageCo
180204

181205
public static int executed = 0;
182206
@Override
183-
public void accept(SpringStageCompletedEvent springStageCompletedEvent) {
207+
public void onApplicationEvent(SpringStageCompletedEvent springStageCompletedEvent) {
184208
executed++;
185209
}
186210
}
187211
```
188212
</TabItem>
189213
<TabItem value="kotlin" label="Kotlin">
190214
```kotlin
191-
class StageCompletedListener : (SpringStageCompletedEvent) -> Unit {
215+
class StageCompletedListener : ApplicationListener<SpringStageCompletedEvent> {
192216

193217
companion object {
194218
var executed = 0
195219
}
196220

197-
override fun invoke(springStageCompletedEvent: SpringStageCompletedEvent) {
221+
override fun onApplicationEvent(event: SpringStageCompletedEvent) {
198222
executed++
199223
}
200224
}

0 commit comments

Comments
 (0)