Skip to content

Commit

Permalink
#52 Persist status for reconciliation runs
Browse files Browse the repository at this point in the history
Persists only Pending|Successful status at the moment; failure handling to be introduced.
  • Loading branch information
chadlwilson committed Dec 13, 2021
1 parent 29b94fb commit 132999d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/kotlin/recce/server/recrun/RecRunRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data class RecRun(
@DateCreated val createdTime: Instant? = null,
@DateUpdated var updatedTime: Instant? = null,
var completedTime: Instant? = null,
@Enumerated(EnumType.STRING) var status: RunStatus = RunStatus.Pending,
@Embedded var summary: MatchStatus? = null
) {
constructor(datasetId: String) : this(null, datasetId)
Expand All @@ -43,6 +44,12 @@ data class RecRun(
}
}

enum class RunStatus {
Pending,
Successful,
Failed
}

@Embeddable
data class MatchStatus(
var sourceOnly: Int = 0,
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/recce/server/recrun/RecRunService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ open class RecRunService(
fun complete(run: RecRun): Mono<RecRun> {
logger.info { "Summarising results for $run" }
return recordRepository.countMatchedByKeyRecRunId(run.id!!)
.map { run.apply { completedTime = Instant.now(); summary = it } }
.map {
run.apply {
completedTime = Instant.now(); summary = it
status = RunStatus.Successful
}
}
.flatMap(runRepository::update)
.doOnNext { logger.info { "Run completed for $it" } }
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/db/migration/V8__REC_RUN_STATUS.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ALTER TABLE reconciliation_run
ADD COLUMN status VARCHAR(20);

-- noinspection SqlWithoutWhere
UPDATE reconciliation_run r
SET status = (
SELECT CASE WHEN completed_time IS NOT NULL THEN 'Successful' ELSE 'Failed' END
FROM reconciliation_run
WHERE id = r.id
);

ALTER TABLE reconciliation_run ALTER status SET NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class DatasetRecServiceIntegrationTest {
assertThat(run.createdTime).isNotNull
assertThat(run.updatedTime).isAfterOrEqualTo(run.createdTime)
assertThat(run.completedTime).isAfterOrEqualTo(run.createdTime)
assertThat(run.status).isEqualTo(RunStatus.Successful)
assertThat(run.summary).isEqualTo(MatchStatus(1, 2, 2, 0))
val expectedMeta = DatasetMeta(
listOf(
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/recce/server/recrun/RecRunServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal class RecRunServiceTest {
StepVerifier.create(RecRunService(runRepository, recordRepository).complete(startedRun))
.assertNext {
assertThat(it.completedTime).isAfterOrEqualTo(it.createdTime)
assertThat(it.status).isEqualTo(RunStatus.Successful)
assertThat(it.summary).isEqualTo(expectedMatchStatus)
}
.verifyComplete()
Expand Down

0 comments on commit 132999d

Please sign in to comment.