Skip to content

Commit

Permalink
feat(orchestrator-api): Extend TaskStepResultRequest with step - adju…
Browse files Browse the repository at this point in the history
…stments to cleaning-service-dummy
  • Loading branch information
martinfkaeser committed Oct 18, 2023
1 parent cdee404 commit 8828ceb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,27 @@ class CleaningServiceDummy(
fun pollForCleaningTasks() {
try {
logger.info { "Starting polling for cleaning tasks from Orchestrator..." }
val step = TaskStep.CleanAndSync

// Step 1: Fetch and reserve the next cleaning request
val cleaningRequest = orchestrationApiClient.goldenRecordTasks
.reserveTasksForStep(TaskStepReservationRequest(amount = 10, TaskStep.CleanAndSync))
.reserveTasksForStep(TaskStepReservationRequest(amount = 10, step))

val cleaningTasks = cleaningRequest.reservedTasks

logger.info { "${cleaningTasks.size} tasks found for cleaning. Proceeding with cleaning..." }

if (cleaningTasks.isNotEmpty()) {

val cleaningResults = cleaningTasks.map { reservedTask ->
// Step 2: Generate dummy cleaning results
processCleaningTask(reservedTask)
}

// Step 3: Send the cleaning result back to the Orchestrator
orchestrationApiClient.goldenRecordTasks.resolveStepResults(TaskStepResultRequest(cleaningResults))
orchestrationApiClient.goldenRecordTasks.resolveStepResults(TaskStepResultRequest(step, cleaningResults))
logger.info { "Cleaning tasks processing completed for this iteration." }
}

} catch (e: Exception) {
logger.error(e) { "Error while processing cleaning task" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class CleaningServiceApiCallsTest @Autowired constructor(

@Test
fun `pollForCleaningTasks should reserve and resolve tasks from orchestrator`() {

// Call the method under test
cleaningServiceDummy.pollForCleaningTasks()

Expand All @@ -91,11 +90,8 @@ class CleaningServiceApiCallsTest @Autowired constructor(

@Test
fun `reserveTasksForStep should return expected response`() {


val expectedResponse = jacksonObjectMapper.writeValueAsString(createSampleTaskStepReservationResponse(businessPartnerWithBpnA))


val result = orchestrationApiClient.goldenRecordTasks.reserveTasksForStep(
TaskStepReservationRequest(amount = 10, TaskStep.Clean)
)
Expand All @@ -105,14 +101,12 @@ class CleaningServiceApiCallsTest @Autowired constructor(
assertEquals(expectedResult, result)

orchestrationApiClient.goldenRecordTasks.resolveStepResults(
TaskStepResultRequest(emptyList())
TaskStepResultRequest(TaskStep.Clean, emptyList())
)

}


fun mockOrchestratorReserveApi() {

// Orchestrator reserve
orchestratorMockApi.stubFor(
post(urlPathEqualTo(ORCHESTRATOR_RESERVE_TASKS_URL))
Expand Down

0 comments on commit 8828ceb

Please sign in to comment.