Skip to content

Conversation

@michel-guillon
Copy link
Contributor

No description provided.

Copy link
Contributor

@vcarluer vcarluer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse @LeopoldCramer method

Copy link
Member

@jreynard-code jreynard-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes ;)

return scenarioRun.withoutSensitiveData()!!
}

private fun deletePreviousSimulationDataIfCurrentSimulationIsSuccessful(currentRun: ScenarioRun) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not write while(true) it's awful.
try something like this

  private fun deletePreviousSimulationDataIfCurrentSimulationIsSuccessful(currentRun: ScenarioRun) {
    val scenarioRunId = currentRun.id!!
    val workspaceId = currentRun.workspaceId!!
    val organizationId = currentRun.organizationId!!
    val scenarioId = currentRun.scenarioId!!
    val csmSimulationRun = currentRun.csmSimulationRun

    var scenarioRunStatus = getScenarioRunStatus(organizationId, scenarioRunId)
    while (
      scenarioRunStatus.state != ScenarioRunState.Successful ||
      scenarioRunStatus.state != ScenarioRunState.Failed ||
      scenarioRunStatus.state != ScenarioRunState.DataIngestionFailure ) {
      logger.info("ScenarioRun {} is still running, waiting for purging data", csmSimulationRun)
      Thread.sleep(10000)
      scenarioRunStatus = getScenarioRunStatus(organizationId, scenarioRunId)
    }

    if (scenarioRunStatus.state == ScenarioRunState.Successful) {
      logger.info("ScenarioRun {} is Successfull => purging data", csmSimulationRun)
      deleteScenarioRunsByScenario(organizationId, workspaceId, scenarioId)
    } else {
      logger.info("ScenarioRun {} is in error {} => no purging data",
        csmSimulationRun,
        scenarioRunStatus.state)
    }

  }

Note that the value 10000 should be configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a sore in the eye
with the following code the intention is clear and neat

private fun deletePreviousSimulationDataIfCurrentSimulationIsSuccessful(currentRun: ScenarioRun) {
while (true) {
Thread.sleep(10000)
val scenarioRunStatus = getScenarioRunStatus(currentRun.organizationId!!, currentRun.id!!)

  if (scenarioRunStatus.state == ScenarioRunState.Successful) {
    deleteScenarioRunsByScenario(
        currentRun.organizationId!!, currentRun.workspaceId!!, currentRun.scenarioId!!)
    return
  } else if (scenarioRunStatus.state == ScenarioRunState.DataIngestionFailure ||
      scenarioRunStatus.state == ScenarioRunState.Failed) {
    logger.info("ScenarioRun {} failed", currentRun.csmSimulationRun)
    break
  }
}

}

@ghost ghost force-pushed the MIG/delete_old_scenariorun_PROD-9734 branch from ff4e5c4 to 27df9f6 Compare October 20, 2022 12:20
@ghost ghost force-pushed the MIG/delete_old_scenariorun_PROD-9734 branch from 948f67d to 24809a4 Compare October 25, 2022 08:58
@jreynard-code jreynard-code self-requested a review October 25, 2022 09:38
Copy link
Member

@jreynard-code jreynard-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vcarluer vcarluer merged commit 18b3f0a into main Oct 25, 2022
@vcarluer vcarluer deleted the MIG/delete_old_scenariorun_PROD-9734 branch October 25, 2022 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants