Skip to content

Commit 961466c

Browse files
committed
Remove Play code from common and simplify AWS Lambda deps
1 parent 50bad72 commit 961466c

19 files changed

Lines changed: 56 additions & 65 deletions

File tree

build.sbt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ val standardSettings = Seq[Setting[_]](
5757
// We should remove this when all transitive dependencies use the same version of scala-xml
5858
// For now this isn't considered an issue due to the compatability between 1.2.x and 2.1.x of the library
5959
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always,
60-
resolvers ++= Seq(
61-
"Guardian GitHub Releases" at "https://guardian.github.com/maven/repo-releases",
62-
"Guardian GitHub Snapshots" at "https://guardian.github.com/maven/repo-snapshots"
63-
),
6460
libraryDependencies ++= Seq(
6561
"com.github.nscala-time" %% "nscala-time" % "3.0.0",
6662
"com.softwaremill.macwire" %% "macros" % "2.6.7" % "provided",
@@ -102,7 +98,6 @@ lazy val common = project
10298
.settings(standardSettings: _*)
10399
.settings(
104100
libraryDependencies ++= Seq(
105-
ws,
106101
"org.typelevel" %% "cats-core" % catsVersion,
107102
"joda-time" % "joda-time" % "2.14.0",
108103
"org.playframework" %% "play-json" % playJsonVersion,
@@ -134,6 +129,14 @@ lazy val common = project
134129
Test / testOptions += Tests.Argument(TestFrameworks.Specs2, "sequential", "true")
135130
)
136131

132+
lazy val commonplay = project
133+
.dependsOn(common, commontest % "test->test").settings(
134+
libraryDependencies ++= Seq(
135+
ws,
136+
"org.playframework" %% "play" % "3.0.7"
137+
)
138+
)
139+
137140
lazy val commonscheduledynamodb = project
138141
.settings(LocalDynamoDBScheduleLambda.settings)
139142
.settings(List(
@@ -152,7 +155,7 @@ lazy val commonscheduledynamodb = project
152155
))
153156

154157
lazy val registration = project
155-
.dependsOn(common, commontest % "test->test")
158+
.dependsOn(commonplay, commontest % "test->test")
156159
.enablePlugins(SystemdPlugin, PlayScala, JDebPackaging)
157160
.settings(standardSettings: _*)
158161
.settings(
@@ -171,7 +174,7 @@ lazy val registration = project
171174
)
172175

173176
lazy val notification = project
174-
.dependsOn(common)
177+
.dependsOn(commonplay)
175178
.dependsOn(commonscheduledynamodb)
176179
.enablePlugins(SystemdPlugin, PlayScala, JDebPackaging)
177180
.settings(standardSettings: _*)
@@ -191,7 +194,7 @@ lazy val notification = project
191194
)
192195

193196
lazy val report = project
194-
.dependsOn(common, commontest % "test->test")
197+
.dependsOn(commonplay, commontest % "test->test")
195198
.enablePlugins(SystemdPlugin, PlayScala, JDebPackaging)
196199
.settings(standardSettings: _*)
197200
.settings(
@@ -235,10 +238,6 @@ def lambda(projectName: String, directoryName: String, mainClassName: Option[Str
235238
.enablePlugins(AssemblyPlugin)
236239
.settings(
237240
organization := "com.gu",
238-
resolvers ++= Seq(
239-
"Guardian GitHub Releases" at "https://guardian.github.com/maven/repo-releases",
240-
"snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
241-
),
242241
libraryDependencies ++= Seq(
243242
"com.amazonaws" % "aws-lambda-java-core" % "1.4.0",
244243
"org.slf4j" % "slf4j-api" % slf4jVersion,
@@ -285,7 +284,6 @@ lazy val schedulelambda = lambda("schedule", "schedulelambda")
285284
lazy val football = lambda("football", "football")
286285
.dependsOn(apiModels % "test->test", apiModels % "compile->compile")
287286
.settings(
288-
resolvers += "Guardian GitHub Releases" at "https://guardian.github.com/maven/repo-releases",
289287
libraryDependencies ++= Seq(
290288
"org.scanamo" %% "scanamo" % "1.0.0-M12-1",
291289
"org.scanamo" %% "scanamo-testkit" % "1.0.0-M12-1" % "test",

common/src/main/scala/db/DatabaseConfig.scala

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package db
22

3-
import java.util.concurrent.Executors
4-
53
import cats.effect.{Async, Blocker, ContextShift, IO}
64
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
75
import doobie.Transactor
8-
import play.api.inject.ApplicationLifecycle
96

10-
import scala.concurrent.{ExecutionContext, Future}
7+
import java.util.concurrent.Executors
8+
import scala.concurrent.ExecutionContext
119

1210
case class JdbcConfig(
1311
driverClassName: String,
@@ -47,14 +45,6 @@ object DatabaseConfig {
4745
val (transactor, _) = transactorAndDataSource(config)
4846
transactor
4947
}
50-
51-
def transactor[F[_] : Async](config: JdbcConfig, applicationLifecycle: ApplicationLifecycle)(implicit cs: ContextShift[F]): Transactor[F] = {
52-
// manually creating the transactor to avoid having it wrapped in a Resource. Resources don't play well with
53-
// Play's way of handling lifecycle
54-
val (transactor, dataSource) = transactorAndDataSource(config)
55-
applicationLifecycle.addStopHook(() => Future.successful(dataSource.close()))
56-
transactor
57-
}
5848
}
5949

6050

common/src/main/scala/db/RegistrationService.scala

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
package db
22

33
import cats.data.NonEmptyList
4-
import cats.effect.internals.IOContextShift
5-
import cats.effect.{Async, ContextShift, IO}
6-
import doobie.free.connection.ConnectionIO
7-
import doobie.util.transactor.Transactor
8-
import fs2.Stream
9-
import models.{Platform, ShardRange, TopicCount}
10-
import play.api.Configuration
11-
import play.api.inject.ApplicationLifecycle
12-
4+
import cats.effect.Async
135
import cats.syntax.all._
146
import doobie.implicits._
15-
16-
import scala.concurrent.ExecutionContext
7+
import doobie.util.transactor.Transactor
8+
import fs2.Stream
9+
import models.{ShardRange, TopicCount}
1710

1811
class RegistrationService[F[_]: Async, S[_[_], _]](repository: RegistrationRepository[F, S], xa: Transactor[F]) {
1912
def findByToken(token: String): S[F, Registration] = repository.findByToken(token)
@@ -55,19 +48,4 @@ object RegistrationService {
5548
val repo = new SqlRegistrationRepository[F](xa)
5649
new RegistrationService[F, Stream](repo, xa)
5750
}
58-
59-
def fromConfig(config: Configuration, applicationLifecycle: ApplicationLifecycle)(implicit ec: ExecutionContext): RegistrationService[IO, Stream] = {
60-
61-
implicit val contextShift: ContextShift[IO] = IO.contextShift(ec)
62-
63-
val masterUrl = config.get[String]("registration.db.url")
64-
val user = config.get[String]("registration.db.user")
65-
val password = config.get[String]("registration.db.password")
66-
val threads = config.get[Int]("registration.db.maxConnectionPoolSize")
67-
68-
val masterJdbcConfig = JdbcConfig("org.postgresql.Driver", masterUrl, user, password, threads)
69-
val masterTransactor = DatabaseConfig.transactor[IO](masterJdbcConfig, applicationLifecycle)
70-
71-
apply(masterTransactor)
72-
}
7351
}

common/src/test/scala/db/RegistrationServiceSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import doobie.implicits._
66
import cats.effect.IO
77
import cats.syntax.all._
88
import doobie.util.transactor.Transactor
9-
import models.{Android, ShardRange, Ios}
9+
import models.{Android, Ios, ShardRange}
1010
import org.specs2.specification.BeforeEach
1111
import fs2.Stream
1212
import org.specs2.concurrent.ExecutionEnv

common/src/main/scala/authentication/AuthAction.scala renamed to commonplay/src/main/scala/authentication/AuthAction.scala

File renamed without changes.

common/src/main/scala/binders/pathbinders/package.scala renamed to commonplay/src/main/scala/binders/pathbinders/package.scala

File renamed without changes.

common/src/main/scala/binders/querystringbinders/package.scala renamed to commonplay/src/main/scala/binders/querystringbinders/package.scala

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)