Skip to content

Commit

Permalink
Handle all finished periodic scenarios waiting for reschedule instead…
Browse files Browse the repository at this point in the history
… of one (#7391)
  • Loading branch information
gskrobisz authored Jan 7, 2025
1 parent 223f484 commit 2623924
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ class SlickPeriodicProcessesRepository(
getLatestDeploymentsForEachSchedule(
processesHavingDeploymentsWithMatchingStatus,
deploymentsPerScheduleMaxCount = 1
).map(_.values.headOption.getOrElse(SchedulesState(Map.empty)))
).map(schedulesForProcessNames =>
SchedulesState(
schedulesForProcessNames.values.map(_.schedules).foldLeft(Map.empty[ScheduleId, ScheduleData])(_ ++ _)
)
)
}

override def getLatestDeploymentsForActiveSchedules(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class PeriodicProcessServiceIntegrationTest
)
service.handleFinished.futureValue

// here we check that scenarios that not fired are still on the "toDeploy" list and finished are not on the list
val toDeployAfterFinish = service.findToBeDeployed.futureValue
toDeployAfterFinish.map(_.periodicProcess.processVersion.processName) should contain only every30MinutesProcessName
service.deactivate(processName).futureValue
Expand Down Expand Up @@ -270,6 +271,58 @@ class PeriodicProcessServiceIntegrationTest
)
}

it should "handleFinished for all finished periodic scenarios waiting for reschedule" in withFixture() { f =>
val timeToTriggerCheck = startTime.plus(2, ChronoUnit.HOURS)
var currentTime = startTime
def service = f.periodicProcessService(currentTime)

service
.schedule(
cronEveryHour,
ProcessVersion.empty.copy(processName = ProcessName("first")),
sampleProcess,
randomProcessActionId
)
.futureValue
service
.schedule(
cronEveryHour,
ProcessVersion.empty.copy(processName = ProcessName("second")),
sampleProcess,
randomProcessActionId
)
.futureValue

currentTime = timeToTriggerCheck

// deploy all
service.findToBeDeployed.futureValue
.foreach(pp => service.deploy(pp).futureValue)

val stateAfterDeploy = service.getLatestDeploymentsForActiveSchedules(1).futureValue
stateAfterDeploy should have size 2

// finish all
stateAfterDeploy.values.foreach(schedulesState => {
val deployment = schedulesState.firstScheduleData.latestDeployments.head
f.delegateDeploymentManagerStub.setStateStatus(
processName,
SimpleStateStatus.Finished,
Some(deployment.id)
)
})
service.handleFinished.futureValue

// check all are rescheduled for next run
val stateAfterFinish = service.getLatestDeploymentsForActiveSchedules(1).futureValue
stateAfterFinish.values.foreach(schedulesState => {
val deployment = schedulesState.firstScheduleData.latestDeployments.head
deployment.state should matchPattern {
case PeriodicProcessDeploymentState(_, _, PeriodicProcessDeploymentStatus.Scheduled) =>
}
})
}

it should "redeploy scenarios that failed on deploy" in withFixture(deploymentRetryConfig =
DeploymentRetryConfig(deployMaxRetries = 1)
) { f =>
Expand Down

0 comments on commit 2623924

Please sign in to comment.