-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save summary at the end of the batch #4872
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
delta/sourcing-psql/src/main/resources/scripts/postgres/drop/drop-tables.ddl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
delta/sourcing-psql/src/main/resources/scripts/postgres/init/V1_10_M09_001__ship_reports.ddl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE IF NOT EXISTS public.ship_runs( | ||
ordering bigserial, | ||
started_at timestamptz NOT NULL, | ||
ended_at timestamptz NOT NULL, | ||
command JSONB NOT NULL, | ||
success boolean NOT NULL, | ||
error text, | ||
report JSONB | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ImportStatus.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/InitShip.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ShipSummaryStore.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.kernel.utils.ThrowableUtils | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors | ||
import ch.epfl.bluebrain.nexus.ship.ShipCommand.RunCommand | ||
import doobie.implicits._ | ||
import doobie.postgres.implicits._ | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.implicits._ | ||
import io.circe.syntax.EncoderOps | ||
|
||
import java.time.Instant | ||
|
||
object ShipSummaryStore { | ||
|
||
def save( | ||
xas: Transactors, | ||
start: Instant, | ||
end: Instant, | ||
command: RunCommand, | ||
reportOrError: Either[Throwable, ImportReport] | ||
): IO[Unit] = { | ||
val success = reportOrError.isRight | ||
val insert = reportOrError match { | ||
case Left(error) => { | ||
val errorMessage = ThrowableUtils.stackTraceAsString(error) | ||
sql""" INSERT INTO ship_runs(started_at, ended_at, command, success, error) VALUES($start, $end, ${command.asJson}, $success, $errorMessage)""" | ||
} | ||
case Right(report) => | ||
sql""" INSERT INTO ship_runs(started_at, ended_at, command , success, report) VALUES($start, $end, ${command.asJson}, $success, ${report.asJson})""" | ||
} | ||
insert.update.run.transact(xas.write).void | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/ShipSummaryStoreSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.Doobie | ||
import ch.epfl.bluebrain.nexus.ship.ShipCommand.RunCommand | ||
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite | ||
import doobie.implicits._ | ||
import doobie.postgres.implicits._ | ||
import munit.AnyFixture | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset | ||
import ch.epfl.bluebrain.nexus.ship.ShipSummaryStoreSuite.ReportRow | ||
import fs2.io.file.Path | ||
|
||
import java.time.Instant | ||
|
||
class ShipSummaryStoreSuite extends NexusSuite with Doobie.Fixture { | ||
|
||
override def munitFixtures: Seq[AnyFixture[_]] = List(doobie) | ||
|
||
private lazy val xas = doobie() | ||
|
||
private def readLast: IO[ReportRow] = | ||
sql"""SELECT started_at, ended_at, success, error is NOT NULL, report is NOT NULL | ||
|FROM public.ship_runs | ||
|ORDER by ordering DESC | ||
|LIMIT 1 | ||
|""".stripMargin | ||
.query[(Instant, Instant, Boolean, Boolean, Boolean)] | ||
.unique | ||
.transact(xas.read) | ||
.map { case (start, end, success, hasError, hasReport) => | ||
ReportRow(start, end, success, hasError, hasReport) | ||
} | ||
|
||
private def assertSave( | ||
start: Instant, | ||
end: Instant, | ||
command: RunCommand, | ||
reportOrError: Either[Throwable, ImportReport] | ||
) = { | ||
for { | ||
_ <- ShipSummaryStore.save(xas, start, end, command, reportOrError) | ||
row <- readLast | ||
} yield { | ||
assertEquals(row.start, start) | ||
assertEquals(row.end, end) | ||
assertEquals(row.success, reportOrError.isRight) | ||
assertEquals(row.hasError, reportOrError.isLeft) | ||
assertEquals(row.hasReport, reportOrError.isRight) | ||
} | ||
} | ||
|
||
private val start = Instant.now().minusSeconds(3600) | ||
private val end = Instant.now() | ||
private val runCommand = RunCommand(Path("/data"), None, Offset.start, RunMode.Local) | ||
|
||
test("Save a failed run") { | ||
val error = new IllegalStateException("BOOM !") | ||
assertSave(start, end, runCommand, Left(error)) | ||
} | ||
|
||
test("Save a successful run") { | ||
val report = ImportReport(Offset.at(5L), Instant.now(), Map.empty) | ||
assertSave(start, end, runCommand, Right(report)) | ||
} | ||
|
||
} | ||
|
||
object ShipSummaryStoreSuite { | ||
|
||
final case class ReportRow(start: Instant, end: Instant, success: Boolean, hasError: Boolean, hasReport: Boolean) | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the existing transactors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I missed to remove the previous one