Skip to content

Commit

Permalink
make access to db instance lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Jun 13, 2024
1 parent aa6862f commit 997d187
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import slick.jdbc.JdbcProfile
this(system, databaseConfig, slickSettings, Clock.systemUTC())

private[projection] val profile: P = databaseConfig.profile
private val db = databaseConfig.db

import profile.api._
import OffsetSerialization.MultipleOffsets
Expand Down Expand Up @@ -92,7 +91,7 @@ import slick.jdbc.JdbcProfile
SingleOffset(ProjectionId(projectionId.name, row.projectionKey), row.manifest, row.offsetStr, row.mergeable))
}

val results = db.run(action)
val results = databaseConfig.db.run(action)

results.map {
case Nil => None
Expand Down Expand Up @@ -181,7 +180,8 @@ import slick.jdbc.JdbcProfile
stmt.execute(sql)
})
}
db.run(DBIO.seq(prepareSchemaDBIO, prepareManagementSchemaDBIO)).map(_ => Done)(ExecutionContexts.parasitic)
databaseConfig.db.run(DBIO.seq(prepareSchemaDBIO, prepareManagementSchemaDBIO))
.map(_ => Done)(ExecutionContexts.parasitic)
}

def dropIfExists(): Future[Done] = {
Expand All @@ -197,7 +197,8 @@ import slick.jdbc.JdbcProfile
stmt.execute(dialect.dropManagementTableStatement)
}
}
db.run(DBIO.seq(prepareSchemaDBIO, prepareManagementSchemaDBIO)).map(_ => Done)(ExecutionContexts.parasitic)
databaseConfig.db.run(DBIO.seq(prepareSchemaDBIO, prepareManagementSchemaDBIO))
.map(_ => Done)(ExecutionContexts.parasitic)
}

def readManagementState(projectionId: ProjectionId)(
Expand All @@ -210,14 +211,14 @@ import slick.jdbc.JdbcProfile
maybeRow.map(row => ManagementState(row.paused))
}

db.run(action)
databaseConfig.db.run(action)
}

def savePaused(projectionId: ProjectionId, paused: Boolean): Future[Done] = {
val millisSinceEpoch = clock.instant().toEpochMilli
val action =
managementTable.insertOrUpdate(ManagementStateRow(projectionId.name, projectionId.key, paused, millisSinceEpoch))

db.run(action).map(_ => Done)(ExecutionContexts.parasitic)
databaseConfig.db.run(action).map(_ => Done)(ExecutionContexts.parasitic)
}
}

0 comments on commit 997d187

Please sign in to comment.