-
Notifications
You must be signed in to change notification settings - Fork 0
[server] parse as stream #133
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ru.trett.rss.server.repositories.ChannelRepository | |||||||||||||||||||||||
| import java.time.OffsetDateTime | ||||||||||||||||||||||||
| import scala.concurrent.duration.DurationInt | ||||||||||||||||||||||||
| import scala.jdk.CollectionConverters.* | ||||||||||||||||||||||||
| import org.http4s.Status | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| class ChannelService(channelRepository: ChannelRepository, client: Client[IO])(using | ||||||||||||||||||||||||
| loggerFactory: LoggerFactory[IO] | ||||||||||||||||||||||||
|
|
@@ -70,23 +71,26 @@ class ChannelService(channelRepository: ChannelRepository, client: Client[IO])(u | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| channel <- | ||||||||||||||||||||||||
| client | ||||||||||||||||||||||||
| .get(url) { response => | ||||||||||||||||||||||||
| response.body.compile.to(Array).flatMap { bytes => | ||||||||||||||||||||||||
| Resource | ||||||||||||||||||||||||
| .fromAutoCloseable( | ||||||||||||||||||||||||
| IO(new XmlReader(new java.io.ByteArrayInputStream(bytes))) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| .use { reader => | ||||||||||||||||||||||||
| parse(reader, link).handleErrorWith { error => | ||||||||||||||||||||||||
| logger.error(error)( | ||||||||||||||||||||||||
| s"Failed to parse the feed: $link" | ||||||||||||||||||||||||
| ) *> IO.none | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| .get[Option[Channel]](url) { | ||||||||||||||||||||||||
| case Status.Successful(r) => { | ||||||||||||||||||||||||
|
Comment on lines
73
to
+75
|
||||||||||||||||||||||||
| r.body | ||||||||||||||||||||||||
| .through(fs2.io.toInputStream) | ||||||||||||||||||||||||
| .evalMap(is => { | ||||||||||||||||||||||||
| Resource | ||||||||||||||||||||||||
| .fromAutoCloseable(IO.blocking(new XmlReader(is))) | ||||||||||||||||||||||||
| .use { reader => parse(reader, link) } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
|
Comment on lines
+78
to
+82
|
||||||||||||||||||||||||
| .compile | ||||||||||||||||||||||||
| .last | ||||||||||||||||||||||||
| .map(_.flatten) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| .handleErrorWith { error => | ||||||||||||||||||||||||
| logger.error(error)(s"Failed to get channel: $link") *> IO.none | ||||||||||||||||||||||||
| case r => | ||||||||||||||||||||||||
| r.as[String] | ||||||||||||||||||||||||
| .map(b => | ||||||||||||||||||||||||
| logger.error( | ||||||||||||||||||||||||
| s"Request failed with status ${r.status.code} and body $b" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| ) *> IO.pure(None) | ||||||||||||||||||||||||
|
Comment on lines
+89
to
+93
|
||||||||||||||||||||||||
| .map(b => | |
| logger.error( | |
| s"Request failed with status ${r.status.code} and body $b" | |
| ) | |
| ) *> IO.pure(None) | |
| .flatTap(b => | |
| logger.error( | |
| s"Request failed with status ${r.status.code} and body $b" | |
| ) | |
| ) | |
| .as(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary braces around the case clause. In Scala 3, braces are optional for case clauses and the opening brace here is inconsistent with the following case clause at line 87 which doesn't use braces.