Al-assad commented on PR #2989:
URL:
https://github.com/apache/incubator-streampark/pull/2989#issuecomment-1706332399
@ChengJie1053 A small tip, it can use this style to consume ZStream safely 😃:
```scala
private val alterStateList =
Array(FlinkAppState.FAILED, FlinkAppState.LOST,
FlinkAppState.RESTARTING, FlinkAppState.FINISHED)
def subscribeJobStatusChange: UIO[Unit] = {
FlinkK8sObserver.evaluatedJobSnaps
.flatSubscribeValues()
// Get Application records and convert JobSnapshot to Application
.mapZIO { jobSnap =>
ZIO
.attemptBlocking {
Option(applicationService.getById(jobSnap.appId))
.map(app => setByJobStatusCV(app, jobSnap))
}
.catchAll { err =>
logError(s"Fail to get Application records: ${err.getMessage}")
.as(None) @@ annotated("appId" -> jobSnap.appId.toString)
}
}
.filter(_.nonEmpty)
.map(_.get)
// Save Application records
.tap { app =>
ZIO
.attemptBlocking(applicationService.persistMetrics(app))
.retryN(3)
.tapError(err => logError(s"Fail to persist Application status:
${err.getMessage}"))
.ignore @@ annotated("appId" -> app.getAppId)
}
// Alert for unhealthy states in parallel
.mapZIOPar(10) { app =>
val state = FlinkAppState.of(app.getState)
ZIO
.attemptBlocking(alertService.alert(app, state))
.when(alterStateList.contains(state))
.retryN(3)
.tapError(err => logError(s"Fail to alter unhealthy application
state: ${err.getMessage}"))
.ignore @@ annotated("appId" -> app.getAppId, "state" ->
state.toString)
}
.runDrain
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]