rabbah commented on a change in pull request #4584: OpenWhisk User Events URL: https://github.com/apache/openwhisk/pull/4584#discussion_r323660442
########## File path: common/scala/src/main/scala/org/apache/openwhisk/core/connector/Message.scala ########## @@ -194,22 +196,53 @@ object EventMessageBody extends DefaultJsonProtocol { case class Activation(name: String, statusCode: Int, - duration: Long, - waitTime: Long, - initTime: Long, + duration: Duration, + waitTime: Duration, + initTime: Duration, kind: String, conductor: Boolean, memory: Int, causedBy: Option[String]) extends EventMessageBody { - val typeName = "Activation" + val typeName = Activation.typeName override def serialize = toJson.compactPrint def toJson = Activation.activationFormat.write(this) + + def status: String = statusCode match { + // Defined in ActivationResponse + case 0 => Activation.statusSuccess + case 1 => Activation.statusApplicationError + case 2 => Activation.statusDeveloperError + case 3 => Activation.statusInternalError + case x => x.toString + } + + def isColdStart: Boolean = initTime != Duration.Zero } object Activation extends DefaultJsonProtocol { + + val typeName = "Activation" def parse(msg: String) = Try(activationFormat.read(msg.parseJson)) + + val statusSuccess = "success" + val statusApplicationError = "application_error" + val statusDeveloperError = "developer_error" + val statusInternalError = "internal_error" + + private implicit val durationFormat = new RootJsonFormat[Duration] { + override def write(obj: Duration): JsValue = obj match { + case o if o.isFinite() => JsNumber(o.toMillis) + case _ => JsNumber.zero + } + + override def read(json: JsValue): Duration = json match { + case JsNumber(n) if n <= 0 => Duration.Zero Review comment: fwiw this would suggest a bug. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services