Unverified Commit 62957f51 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

parse timestamps without milliseconds


Signed-off-by: Sebastian Schüpbach's avatarSebastian Schüpbach <sebastian.schuepbach@unibas.ch>
parent ba08b4f2
Pipeline #17879 passed with stages
in 5 minutes and 29 seconds
......@@ -37,13 +37,16 @@ case class Report(msgKey: String,
object Report {
private val dateFormatter = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss.SSS")
private val shortDateFormatter = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss")
def apply(consumerRecord: ConsumerRecord[String, String]): Try[Report] = Try {
val json = Try(ujson.read(consumerRecord.value())).getOrElse(throw new ParserException("JSON is not valid!"))
val id = Try(json.obj("id").str).getOrElse(throw new ParserException("No `id` field in JSON obj"))
val step = Try(json.obj("step").str).getOrElse(throw new ParserException("No `step` field in JSON obj"))
val timestampString = Try(json.obj("timestamp").str).getOrElse(throw new ParserException("No `timestamp` field in JSON obj"))
val timestamp = Try(dateFormatter.parse(timestampString)).getOrElse(throw new ParserException("No valid timestamp"))
val timestamp = Try(dateFormatter.parse(timestampString))
.orElse(Try(shortDateFormatter.parse(timestampString)))
.getOrElse(throw new ParserException("No valid timestamp"))
val status = Try(json.obj("status").str).getOrElse(throw new ParserException("No `status` field in JSON obj"))
val message = Try(json.obj("message").str).getOrElse(throw new ParserException("No `message` field in JSON obj"))
val headers = consumerRecord.headers()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment