Skip to content
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

Dont crash when elastic search down #254

Merged
merged 3 commits into from
Jul 2, 2024
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
5 changes: 4 additions & 1 deletion modules/ingestor/src/main/scala/ingestor.team.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ object TeamIngestor:
private def storeBulk(docs: List[Document]): IO[Unit] =
val sources = docs.toSources
info"Received ${docs.size} teams to index" *>
elastic.storeBulk(index, sources) *> info"Indexed ${sources.size} teams"
elastic
.storeBulk(index, sources)
.handleErrorWith: e =>
Logger[IO].error(e)(s"Failed to index teams: ${docs.map(_.id).mkString(", ")}")
.whenA(sources.nonEmpty)
*> info"Indexed ${sources.size} teams"

private def saveLastIndexedTimestamp(time: Instant): IO[Unit] =
store.put(index.value, time)
Expand Down
10 changes: 5 additions & 5 deletions modules/ingestor/src/main/scala/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ def range(field: String)(since: Instant, until: Option[Instant]): Filter =
until.fold(gtes)(until => gtes.and(Filter.lt(field, until)))

extension (elastic: ESClient[IO])

@scala.annotation.targetName("deleteManyWithIds")
def deleteMany(index: Index, ids: List[Id])(using Logger[IO]): IO[Unit] =
elastic
.deleteMany(index, ids)
.flatTap(_ => Logger[IO].info(s"Deleted ${ids.size} ${index.value}s"))
.handleErrorWith: e =>
Logger[IO].error(e)(s"Failed to delete ${index.value}s: ${ids.map(_.value).mkString(", ")}")
Logger[IO].error(e)(s"Failed to delete ${index.value}: ${ids.map(_.value).mkString(", ")}")
.whenA(ids.nonEmpty)

@scala.annotation.targetName("deleteManyWithDocs")
def deleteMany(index: Index, events: List[Document])(using Logger[IO]): IO[Unit] =
info"Received ${events.size} forum posts to delete" *>
deleteMany(index, events.flatMap(_.id).map(Id.apply))
.whenA(events.nonEmpty)
info"Received ${events.size} ${index.value} to delete" *>
deleteMany(index, events.flatMap(_.id).map(Id.apply)).whenA(events.nonEmpty)

@scala.annotation.targetName("deleteManyWithChanges")
def deleteMany(index: Index, events: List[ChangeStreamDocument[Document]])(using Logger[IO]): IO[Unit] =
info"Received ${events.size} forum posts to delete" *>
info"Received ${events.size} ${index.value} to delete" *>
deleteMany(index, events.flatMap(_.docId).map(Id.apply)).whenA(events.nonEmpty)
Loading