0
S3バケットから2つのJSONファイルをマージしようとしています。最初のファイルは正常に取得されますが、2番目のファイルは正常ではありません。Scala:AmazonS3Client getObject Futuresを使用して2つのJSONファイルをマージする
val eventLogJsonFuture = Future(new AmazonS3Client(credentials))
.map(_.getObject(logBucket, logDirectory + "/" + id + "/event_log.json"))
.map(_.getObjectContent)
.map(Source.fromInputStream(_))
.map(_.mkString)
.map(Json.parse) map { archiveEvents =>
Json.toJson(Json.obj("success" -> true, "data" -> archiveEvents))
} recover {
case NonFatal(error) =>
Json.obj("success" -> false, "errorCode" -> "archive_does_not_exist", "message" -> error.getMessage)
}
val infoJsonFuture = Future(new AmazonS3Client(credentials))
.map(_.getObject(logBucket, logDirectory + "/" + id + "/info.json"))
.map(_.getObjectContent)
.map(Source.fromInputStream(_))
.map(_.mkString)
.map(Json.parse) map { archiveInfo =>
Json.toJson(Json.obj("success" -> true, "data" -> archiveInfo))
} recover {
case NonFatal(error) =>
Json.obj("success" -> false, "errorCode" -> "archive_does_not_exist", "message" -> error.getMessage)
}
val combinedJson = for {
eventLogJson <- eventLogJsonFuture
infoJson <- infoJsonFuture
}
yield {
Json.obj("info" -> infoJson, "events" -> eventLogJson)
}
これは、結果はJSONのように見えるものです...
はこれを書いている別の(よりよい?)方法はありますか?
?エレガントに見えます。 –
問題は、infoJsonFutureがNonFatalエラーをスローしているということです。ファイルがS3上に本当に存在する場合、「Input length = 1」です。 AmazonS3Clientは2つの独立したスレッドで非同期に実行できないことがありますか? –
別のソースからJSONを3部待つべきですか? –