@@ -40,6 +40,7 @@ import maestro.orchestra.yaml.YamlCommandReader
40
40
import maestro.utils.Insight
41
41
import maestro.utils.Insights
42
42
import maestro.utils.MaestroTimer
43
+ import maestro.utils.NoopInsights
43
44
import maestro.utils.StringUtils.toRegexSafe
44
45
import okhttp3.OkHttpClient
45
46
import okio.Buffer
@@ -76,11 +77,12 @@ class Orchestra(
76
77
private val lookupTimeoutMs : Long = 17000L ,
77
78
private val optionalLookupTimeoutMs : Long = 7000L ,
78
79
private val httpClient : OkHttpClient ? = null ,
80
+ private val insights : Insights = NoopInsights ,
79
81
private val onFlowStart : (List <MaestroCommand >) -> Unit = {},
80
82
private val onCommandStart : (Int , MaestroCommand ) -> Unit = { _, _ -> },
81
83
private val onCommandComplete : (Int , MaestroCommand ) -> Unit = { _, _ -> },
82
84
private val onCommandFailed : (Int , MaestroCommand , Throwable ) -> ErrorResolution = { _, _, e -> throw e },
83
- private val onCommandWarned : (Int , MaestroCommand ) -> Unit = { _, _ -> },
85
+ private val onCommandWarned : (Int , MaestroCommand ) -> Unit = { _, _ -> },
84
86
private val onCommandSkipped : (Int , MaestroCommand ) -> Unit = { _, _ -> },
85
87
private val onCommandReset : (MaestroCommand ) -> Unit = {},
86
88
private val onCommandMetadataUpdate : (MaestroCommand , CommandMetadata ) -> Unit = { _, _ -> },
@@ -186,7 +188,7 @@ class Orchestra(
186
188
)
187
189
)
188
190
}
189
- Insights .onInsightsUpdated(callback)
191
+ insights .onInsightsUpdated(callback)
190
192
191
193
try {
192
194
try {
@@ -199,7 +201,7 @@ class Orchestra(
199
201
}
200
202
} catch (ignored: CommandWarned ) {
201
203
// Swallow exception, but add a warning as an insight
202
- Insights .report(Insight (message = ignored.message, level = Insight .Level .WARNING ))
204
+ insights .report(Insight (message = ignored.message, level = Insight .Level .WARNING ))
203
205
onCommandWarned(index, command)
204
206
} catch (ignored: CommandSkipped ) {
205
207
// Swallow exception
@@ -210,8 +212,9 @@ class Orchestra(
210
212
ErrorResolution .FAIL -> return false
211
213
ErrorResolution .CONTINUE -> {} // Do nothing
212
214
}
215
+ } finally {
216
+ insights.unregisterListener(callback)
213
217
}
214
- Insights .unregisterListener(callback)
215
218
}
216
219
return true
217
220
}
@@ -690,7 +693,7 @@ class Orchestra(
690
693
}
691
694
} catch (ignored: CommandWarned ) {
692
695
// Swallow exception, but add a warning as an insight
693
- Insights .report(Insight (message = ignored.message, level = Insight .Level .WARNING ))
696
+ insights .report(Insight (message = ignored.message, level = Insight .Level .WARNING ))
694
697
onCommandWarned(index, command)
695
698
false
696
699
} catch (ignored: CommandSkipped ) {
0 commit comments