Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions modules/ingestor/src/main/scala/app.config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import cats.effect.IO
import cats.syntax.all.*
import ciris.*

import java.time.Instant
import scala.concurrent.duration.*

import CirisCodec.given

object AppConfig:

def load: IO[AppConfig] = appConfig.load[IO]
Expand Down Expand Up @@ -50,21 +53,18 @@ case class IngestorConfig(
)

object IngestorConfig:
case class Forum(batchSize: Int, timeWindows: Int, startAt: Option[Long], maxPostLength: Int)
case class Team(batchSize: Int, timeWindows: Int, startAt: Option[Long])
case class Study(batchSize: Int, startAt: Option[Long], interval: FiniteDuration, databaseName: String)
case class Game(batchSize: Int, timeWindows: Int, startAt: Option[Long])
case class Forum(batchSize: Int, timeWindows: Int, startAt: Option[Instant], maxPostLength: Int)
case class Team(batchSize: Int, timeWindows: Int, startAt: Option[Instant])
case class Study(batchSize: Int, startAt: Option[Instant], interval: FiniteDuration, databaseName: String)
case class Game(batchSize: Int, timeWindows: Int, startAt: Option[Instant])

private object Forum:
private def batchSize =
env("INGESTOR_FORUM_BATCH_SIZE").or(prop("ingestor.forum.batch.size")).as[Int].default(100)
private def timeWindows =
env("INGESTOR_FORUM_TIME_WINDOWS").or(prop("ingestor.forum.time.windows")).as[Int].default(10)
private def startAt =
env("INGESTOR_FORUM_START_AT")
.or(prop("ingestor.forum.start.at"))
.as[Long]
.option
env("INGESTOR_FORUM_START_AT").or(prop("ingestor.forum.start.at")).as[Instant].option
private def maxPostLength =
env("INGESTOR_FORUM_MAX_POST_LENGTH").or(prop("ingestor.forum.max.post.length")).as[Int].default(5_000)
def config = (batchSize, timeWindows, startAt, maxPostLength).parMapN(Forum.apply)
Expand All @@ -75,14 +75,14 @@ object IngestorConfig:
private def timeWindows =
env("INGESTOR_TEAM_TIME_WINDOWS").or(prop("ingestor.team.time.windows")).as[Int].default(10)
private def startAt =
env("INGESTOR_TEAM_START_AT").or(prop("ingestor.team.start.at")).as[Long].option
env("INGESTOR_TEAM_START_AT").or(prop("ingestor.team.start.at")).as[Instant].option
def config = (batchSize, timeWindows, startAt).mapN(Team.apply)

private object Study:
private def batchSize =
env("INGESTOR_STUDY_BATCH_SIZE").or(prop("ingestor.study.batch.size")).as[Int].default(100)
private def startAt =
env("INGESTOR_STUDY_START_AT").or(prop("ingestor.study.start.at")).as[Long].option
env("INGESTOR_STUDY_START_AT").or(prop("ingestor.study.start.at")).as[Instant].option
private def interval =
env("INGESTOR_STUDY_INTERVAL")
.or(prop("ingestor.study.interval"))
Expand All @@ -97,7 +97,12 @@ object IngestorConfig:
private def timeWindows =
env("INGESTOR_GAME_TIME_WINDOWS").or(prop("ingestor.game.time.windows")).as[Int].default(10)
private def startAt =
env("INGESTOR_GAME_START_AT").or(prop("ingestor.game.start.at")).as[Long].option
env("INGESTOR_GAME_START_AT").or(prop("ingestor.game.start.at")).as[Instant].option
def config = (batchSize, timeWindows, startAt).mapN(Game.apply)

def config = (Forum.config, Team.config, Study.config, Game.config).mapN(IngestorConfig.apply)

object CirisCodec:
given ConfigDecoder[String, Instant] = ConfigDecoder[String]
.as[Long]
.map(Instant.ofEpochSecond)
2 changes: 1 addition & 1 deletion modules/ingestor/src/main/scala/ingestor.forum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object ForumIngestor:
*> info"Stored last indexed time ${time.getEpochSecond} for $index"

private def startAt: IO[Option[Instant]] =
config.startAt.fold(store.get(index.value))(Instant.ofEpochSecond(_).some.pure[IO])
config.startAt.fold(store.get(index.value))(_.some.pure[IO])

// Fetches topic names by their ids
private def topicByIds(ids: Seq[String]): IO[Map[String, String]] =
Expand Down
2 changes: 1 addition & 1 deletion modules/ingestor/src/main/scala/ingestor.game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ object GameIngestor:
*> info"Stored last indexed time ${time.getEpochSecond} for $index"

private def startAt: IO[Option[Instant]] =
config.startAt.fold(store.get(index.value))(Instant.ofEpochSecond(_).some.pure[IO])
config.startAt.fold(store.get(index.value))(_.some.pure[IO])

object F:
val createdAt = "ca"
Expand Down
3 changes: 1 addition & 2 deletions modules/ingestor/src/main/scala/ingestor.study.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ object StudyIngestor:
def intervalStream: fs2.Stream[IO, (Instant, Instant)] =
fs2.Stream
.eval:
config.startAt
.fold(store.get(index.value))(Instant.ofEpochSecond(_).some.pure[IO])
config.startAt.fold(store.get(index.value))(_.some.pure[IO])
.flatMap: startAt =>
startAt.fold(fs2.Stream.empty)(since => fs2.Stream(since))
++ fs2.Stream
Expand Down
2 changes: 1 addition & 1 deletion modules/ingestor/src/main/scala/ingestor.team.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ object TeamIngestor:
*> info"Stored last indexed time ${time.getEpochSecond} for $index"

private def startAt: IO[Option[Instant]] =
config.startAt.fold(store.get(index.value))(Instant.ofEpochSecond(_).some.pure[IO])
config.startAt.fold(store.get(index.value))(_.some.pure[IO])

private def changeStream(since: Option[Instant]): fs2.Stream[IO, List[ChangeStreamDocument[Document]]] =
// skip the first event if we're starting from a specific timestamp
Expand Down
Loading