-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save scope initialization errors (#4620)
- Loading branch information
1 parent
6644f89
commit e868da8
Showing
14 changed files
with
219 additions
and
26 deletions.
There are no files selected for viewing
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
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
45 changes: 45 additions & 0 deletions
45
...main/scala/ch/epfl/bluebrain/nexus/delta/sdk/projects/ScopeInitializationErrorStore.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,45 @@ | ||
package ch.epfl.bluebrain.nexus.delta.sdk.projects | ||
|
||
import cats.effect.{Clock, IO} | ||
import cats.implicits._ | ||
import ch.epfl.bluebrain.nexus.delta.kernel.Logger | ||
import ch.epfl.bluebrain.nexus.delta.sdk.error.ServiceError.ScopeInitializationFailed | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, ProjectRef} | ||
import doobie.implicits._ | ||
import doobie.postgres.implicits._ | ||
|
||
trait ScopeInitializationErrorStore { | ||
|
||
/** | ||
* Save a scope initialization error | ||
* @param entityType | ||
* type of the entity this error is for | ||
* @param project | ||
* project for which the error occurred | ||
* @param e | ||
* the error to save | ||
*/ | ||
def save(entityType: EntityType, project: ProjectRef, e: ScopeInitializationFailed): IO[Unit] | ||
|
||
} | ||
|
||
object ScopeInitializationErrorStore { | ||
|
||
private val logger = Logger[ScopeInitializationErrorStore] | ||
|
||
def apply(xas: Transactors, clock: Clock[IO]): ScopeInitializationErrorStore = | ||
(entityType: EntityType, project: ProjectRef, e: ScopeInitializationFailed) => { | ||
clock.realTimeInstant | ||
.flatMap { instant => | ||
sql""" | ||
|INSERT INTO scope_initialization_errors (type, org, project, message, instant) | ||
|VALUES ($entityType, ${project.organization}, ${project.project}, ${e.getMessage}, $instant) | ||
|""".stripMargin.update.run.void.transact(xas.write) | ||
} | ||
.onError { e => | ||
logger.error(e)(s"Failed to save error for '$entityType' initialization step on project '$project'") | ||
} | ||
} | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
.../sdk/src/test/scala/ch/epfl/bluebrain/nexus/delta/sdk/FailingScopeInitializationLog.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,25 @@ | ||
package ch.epfl.bluebrain.nexus.delta.sdk | ||
import cats.effect.IO | ||
import ch.epfl.bluebrain.nexus.delta.sdk.error.ServiceError.ScopeInitializationFailed | ||
import ch.epfl.bluebrain.nexus.delta.sdk.organizations.model.Organization | ||
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.Project | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, Identity} | ||
|
||
/** | ||
* Simple implementation that records created orgs and projects | ||
*/ | ||
final class FailingScopeInitializationLog extends ScopeInitialization { | ||
|
||
override def onOrganizationCreation( | ||
organization: Organization, | ||
subject: Identity.Subject | ||
): IO[Unit] = | ||
IO.raiseError(ScopeInitializationFailed("failed at org creation")) | ||
override def onProjectCreation( | ||
project: Project, | ||
subject: Identity.Subject | ||
): IO[Unit] = | ||
IO.raiseError(ScopeInitializationFailed("failed at project creation")) | ||
|
||
override def entityType: EntityType = EntityType("failingScopeInitializationLog") | ||
} |
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
Oops, something went wrong.