Skip to content

Commit

Permalink
Refactor nested conditional statements by match case
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen committed Oct 15, 2024
1 parent c2ab09f commit 7eb7eb3
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,22 @@ class FlintSparkIndexMonitor(
override def run(): Unit = {
logInfo(s"Scheduler trigger index monitor task for $indexName")
try {
if (isStreamingJobActive(indexName)) {
if (flintClient.exists(indexName)) {
logInfo("Streaming job is still active")
val isJobActive = isStreamingJobActive(indexName)
val indexExists = flintClient.exists(indexName)

(isJobActive, indexExists) match {
case (true, true) =>
logInfo("Streaming job is active and index exists")
flintMetadataLogService.recordHeartbeat(indexName)
} else {
logWarning("Streaming job is active but data is deleted")

case (true, false) =>
logWarning("Streaming job is active but index is deleted")
stopStreamingJobAndMonitor(indexName)
}
} else {
logError("Streaming job is not active. Cancelling monitor task")
stopMonitor(indexName)
logInfo("Index monitor task is cancelled")

case (false, _) =>
logError("Streaming job is not active. Cancelling monitor task")
stopMonitor(indexName)
logInfo("Index monitor task is cancelled")
}
errorCnt = 0 // Reset counter if no error
} catch {
Expand Down

0 comments on commit 7eb7eb3

Please sign in to comment.