diff --git a/build.gradle.kts b/build.gradle.kts index 8000e71..2778598 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "org.veupathdb.lib" -version = "1.0.1" +version = "1.1.0" repositories { mavenCentral() @@ -28,19 +28,19 @@ dependencies { implementation(kotlin("stdlib-jdk8")) // Jackson and modules (gotta catch em all) - implementation("com.fasterxml.jackson.core:jackson-databind:2.13.1") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-json-org:2.13.1") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.1") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.1") - implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.1") - implementation("com.fasterxml.jackson.module:jackson-module-parameter-names:2.13.1") + implementation("com.fasterxml.jackson.core:jackson-databind:2.13.3") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-json-org:2.13.3") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.3") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3") + implementation("com.fasterxml.jackson.module:jackson-module-parameter-names:2.13.3") // Logging - implementation("org.apache.logging.log4j:log4j-core:2.17.0") - implementation("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.0") + implementation("org.apache.logging.log4j:log4j-core:2.17.2") + implementation("org.apache.logging.log4j:log4j-slf4j18-impl:2.17.2") implementation("org.veupathdb.lib:hash-id:1.0.2") - implementation("com.rabbitmq:amqp-client:5.14.0") + implementation("com.rabbitmq:amqp-client:5.14.2") } kotlin { diff --git a/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/model/JobDispatch.kt b/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/model/JobDispatch.kt index 9742c0e..c182c4c 100644 --- a/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/model/JobDispatch.kt +++ b/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/model/JobDispatch.kt @@ -7,6 +7,8 @@ import org.veupathdb.lib.rabbit.jobs.serialization.Json import org.veupathdb.lib.rabbit.jobs.serialization.JsonDeserializable import org.veupathdb.lib.rabbit.jobs.serialization.JsonKey import org.veupathdb.lib.rabbit.jobs.serialization.JsonSerializable +import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter /** * Job Request/Dispatch @@ -34,13 +36,15 @@ import org.veupathdb.lib.rabbit.jobs.serialization.JsonSerializable */ data class JobDispatch( val jobID: HashID, - val type: String, - val body: JsonNode?, + val body: JsonNode? = null, + val type: String = "", + val dispatched: OffsetDateTime = OffsetDateTime.now() ) : JsonSerializable { override fun toJson() = Json.new { put(JsonKey.JobID, jobID.string) put(JsonKey.Type, type) + put(JsonKey.Dispatched, dispatched.toString()) putPOJO(JsonKey.Body, body) } @@ -50,27 +54,38 @@ data class JobDispatch( companion object : JsonDeserializable { @JvmStatic override fun fromJson(json: ObjectNode): JobDispatch { + + // Fields must be present if (!json.has(JsonKey.JobID)) throw IllegalStateException("Job dispatch has no ${JsonKey.JobID} field!") if (!json.has(JsonKey.Type)) throw IllegalStateException("Job dispatch has no ${JsonKey.Type} field!") if (!json.has(JsonKey.Body)) throw IllegalStateException("Job dispatch has no ${JsonKey.Body} field!") + if (!json.has(JsonKey.Dispatched)) + throw IllegalStateException("Job dispatch has no ${JsonKey.Dispatched} field!") + // Only body field may be null if (json.get(JsonKey.JobID).isNull) throw IllegalStateException("Job dispatch has a null ${JsonKey.JobID} field!") if (json.get(JsonKey.Type).isNull) throw IllegalStateException("Job dispatch has a null ${JsonKey.Type} field!") + if (json.get(JsonKey.Dispatched).isNull) + throw IllegalStateException("Job dispatch has a null ${JsonKey.Dispatched} field!") + // Fields must be the correct type if (!json.get(JsonKey.JobID).isTextual) throw IllegalStateException("Job dispatch has a non-textual ${JsonKey.JobID} field!") if (!json.get(JsonKey.Type).isTextual) throw IllegalStateException("Job dispatch has a non-textual ${JsonKey.Type} field!") + if (!json.get(JsonKey.Dispatched).isTextual) + throw IllegalStateException("Job dispatch has a non-textual ${JsonKey.Dispatched} field!") return JobDispatch( HashID(json.get(JsonKey.JobID).textValue()), + json.get(JsonKey.Body), json.get(JsonKey.Type).textValue(), - json.get(JsonKey.Body) + OffsetDateTime.parse(json.get(JsonKey.Dispatched).textValue()) ) } } diff --git a/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/serialization/JsonKey.kt b/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/serialization/JsonKey.kt index 0b0450f..3d1935d 100644 --- a/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/serialization/JsonKey.kt +++ b/src/main/kotlin/org/veupathdb/lib/rabbit/jobs/serialization/JsonKey.kt @@ -1,9 +1,10 @@ package org.veupathdb.lib.rabbit.jobs.serialization internal object JsonKey { - const val Body = "body" - const val Code = "code" - const val JobID = "jobID" - const val Message = "message" - const val Type = "type" + const val Body = "body" + const val Code = "code" + const val JobID = "jobID" + const val Message = "message" + const val Type = "type" + const val Dispatched = "dispatched" } \ No newline at end of file diff --git a/test/server/src/main/kotlin/main.kt b/test/server/src/main/kotlin/main.kt index ffc0007..e305dcc 100644 --- a/test/server/src/main/kotlin/main.kt +++ b/test/server/src/main/kotlin/main.kt @@ -21,7 +21,7 @@ fun main() { conFac.dispatch(JobDispatch( HashID("01020304050607080102030405060708"), + TextNode("foo"), "something", - TextNode("foo") )) } \ No newline at end of file