Skip to content
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

update rabbit dependency and add dispatch timestamp #3

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "org.veupathdb.lib"
version = "1.0.1"
version = "1.1.0"

repositories {
mavenCentral()
Expand All @@ -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 {
Expand Down
21 changes: 18 additions & 3 deletions src/main/kotlin/org/veupathdb/lib/rabbit/jobs/model/JobDispatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ObjectNode> {
put(JsonKey.JobID, jobID.string)
put(JsonKey.Type, type)
put(JsonKey.Dispatched, dispatched.toString())
putPOJO(JsonKey.Body, body)
}

Expand All @@ -50,27 +54,38 @@ data class JobDispatch(
companion object : JsonDeserializable<ObjectNode, JobDispatch> {
@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())
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion test/server/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fun main() {

conFac.dispatch(JobDispatch(
HashID("01020304050607080102030405060708"),
TextNode("foo"),
"something",
TextNode("foo")
))
}