Skip to content

Commit

Permalink
Periodic scenario status query improvement (#7386)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoworko authored Jan 3, 2025
1 parent 8fdf5b6 commit 9b4a542
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,14 @@ class DeploymentService(
.map {
case process if process.isFragment => DBIO.successful(process)
case process =>
val prefetchedStatusDetails = for {
prefetchedStatusDetailsForProcessingTypes <- prefetchedStates.get(process.processingType)
prefetchedStatusDetails <- prefetchedStatusDetailsForProcessingTypes.get(process.name)
} yield prefetchedStatusDetails
prefetchedStatusDetails match {
val prefetchedState = for {
prefetchedStatesForProcessingType <- prefetchedStates.get(process.processingType)
// State is prefetched for all scenarios for the given processing type.
// If there is no information available for a specific scenario name,
// then it means that DM is not aware of this scenario, and we should default to List.empty[StatusDetails].
prefetchedState = prefetchedStatesForProcessingType.getOrElse(process.name, List.empty)
} yield prefetchedState
prefetchedState match {
case Some(prefetchedStatusDetails) =>
getProcessStateUsingPrefetchedStatus(
process.toEntity,
Expand All @@ -466,7 +469,6 @@ class DeploymentService(
None,
).map(state => process.copy(state = Some(state)))
}

}
.sequence[DB, ScenarioWithDetails]
} yield processesWithState
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* [#7376](https://github.com/TouK/nussknacker/pull/7376) Previously, when count was > 1, the value was evaluated once
and emitted times count. For example: if the value was evaluated to be a random UUID and count was 5, one UUID was
generated and emitted 5 times. Now in one count batch each value is evaluated separately.
* [#7386](https://github.com/TouK/nussknacker/pull/7386) Improve Periodic DeploymentManager db queries, continuation of [#7323](https://github.com/TouK/nussknacker/pull/7323)

## 1.18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ class PeriodicDeploymentManager private[periodic] (
deployedVersionId: Option[VersionId],
currentlyPresentedVersionId: Option[VersionId],
): Future[ProcessState] = {
val statusDetails = statusDetailsList.head
val statusDetails = statusDetailsList match {
case head :: _ =>
head
case Nil =>
val status = PeriodicProcessStatus(List.empty, List.empty)
status.mergedStatusDetails.copy(status = status)
}
// TODO: add "real" presentation of deployments in GUI
val mergedStatus = processStateDefinitionManager
.processState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,11 @@ class PeriodicProcessService(
override def getAllProcessesStates()(
implicit freshnessPolicy: DataFreshnessPolicy
): Future[WithDataFreshnessStatus[Map[ProcessName, List[StatusDetails]]]] = {
supported.getAllProcessesStates().flatMap { statusesWithFreshness =>
mergeStatusWithDeployments(statusesWithFreshness.value).map { statusDetails =>
statusesWithFreshness.map(_.flatMap { case (name, _) =>
statusDetails.get(name).map(statusDetails => (name, List(statusDetails)))
})
}
}
for {
allStatusDetailsInDelegate <- supported.getAllProcessesStates()
allStatusDetailsInPeriodic <- mergeStatusWithDeployments(allStatusDetailsInDelegate.value)
result = allStatusDetailsInPeriodic.map { case (name, status) => (name, List(status)) }
} yield allStatusDetailsInDelegate.map(_ => result)
}

}
Expand Down

0 comments on commit 9b4a542

Please sign in to comment.