Skip to content

Instantly share code, notes, and snippets.

@ndemengel
Last active April 26, 2020 10:49
Show Gist options
  • Save ndemengel/1faadb383b1e8acd5c1bbfca3c8e6aca to your computer and use it in GitHub Desktop.
Save ndemengel/1faadb383b1e8acd5c1bbfca3c8e6aca to your computer and use it in GitHub Desktop.
Commanq queue: a command and its companion specification class
@Component
class PushTransactionForInvoice(
private val transactionPushService: TransactionPushService
) : Command(PushTransactionForInvoiceSpec::class) {
override fun execute(arguments: Map<String, Any?>): CommandExecutionResult {
val invoiceId = InvoiceId(arguments["invoiceId"] as String)
val transactionId = TransactionId(arguments["transactionId"] as String)
transactionPushService.pushTransactionForInvoice(transactionId, invoiceId)
// May return FailureOnOurSide or FailureOnProviderSide as well.
// Any exception will be caught and considered a FailureOnOurSide, unless
// CircuitBreaking.considerExceptionAsFailureIf tells it's a FailureOnProviderSide
return Success
}
}
class PushTransactionForInvoiceSpec(
transactionId: TransactionId,
invoiceId: InvoiceId
) : CommandSpecification(mapOf(
"invoiceId" to invoiceId.get(),
"transactionId" to transactionId.get()
)) {
companion object {
val COMMAND_NAME = "pushTransactionForInvoice"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment