Skip to content

Commit

Permalink
removed superfluous try block
Browse files Browse the repository at this point in the history
  • Loading branch information
octonato committed Dec 18, 2024
1 parent 59de3ba commit 5c22d14
Showing 1 changed file with 33 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,52 +143,50 @@ class ReflectiveWorkflowRouter[S, W <: Workflow[S]](
commandContext: CommandContext,
executionContext: ExecutionContext): Future[BytesPayload] = {

val workflow = instanceFactory(workflowContext)
implicit val ec: ExecutionContext = executionContext

try {
// if runtime doesn't have a state to provide, we fall back to user's own defined empty state
val decodedState = decodeUserState(userState).getOrElse(workflow.emptyState())
workflow._internalSetup(decodedState, commandContext, timerScheduler)
workflow.definition().findByName(stepName).toScala match {
case Some(call: AsyncCallStep[_, _, _]) =>
val decodedInput = input match {
case Some(inputValue) => decodeInput(inputValue, call.callInputClass)
case None => null // to meet a signature of supplier expressed as a function
}
val workflow = instanceFactory(workflowContext)
// if runtime doesn't have a state to provide, we fall back to user's own defined empty state
val decodedState = decodeUserState(userState).getOrElse(workflow.emptyState())
workflow._internalSetup(decodedState, commandContext, timerScheduler)

workflow.definition().findByName(stepName).toScala match {
case Some(call: AsyncCallStep[_, _, _]) =>
val decodedInput = input match {
case Some(inputValue) => decodeInput(inputValue, call.callInputClass)
case None => null // to meet a signature of supplier expressed as a function
}

val future = call.callFunc
.asInstanceOf[JFunc[Any, CompletionStage[Any]]]
.apply(decodedInput)
.asScala
val future = call.callFunc
.asInstanceOf[JFunc[Any, CompletionStage[Any]]]
.apply(decodedInput)
.asScala

future.map(serializer.toBytes)
future.map(serializer.toBytes)

case Some(any) => Future.failed(WorkflowStepNotSupported(any.getClass.getSimpleName))
case None => Future.failed(WorkflowStepNotFound(stepName))
}
case Some(any) => Future.failed(WorkflowStepNotSupported(any.getClass.getSimpleName))
case None => Future.failed(WorkflowStepNotFound(stepName))
}
}

final def getNextStep(stepName: String, result: BytesPayload, userState: Option[BytesPayload]): TransitionalResult = {

val workflow = instanceFactory(workflowContext)
try {
// if runtime doesn't have a state to provide, we fall back to user's own defined empty state
val decodedState = decodeUserState(userState).getOrElse(workflow.emptyState())
workflow._internalSetup(decodedState)
workflow.definition().findByName(stepName).toScala match {
case Some(call: AsyncCallStep[_, _, _]) =>
val effect =
call.transitionFunc
.asInstanceOf[JFunc[Any, TransitionalEffect[Any]]]
.apply(decodeInput(result, call.transitionInputClass))

TransitionalResult(effect)

case Some(any) => throw WorkflowStepNotSupported(any.getClass.getSimpleName)
case None => throw WorkflowStepNotFound(stepName)
}

// if runtime doesn't have a state to provide, we fall back to user's own defined empty state
val decodedState = decodeUserState(userState).getOrElse(workflow.emptyState())
workflow._internalSetup(decodedState)
workflow.definition().findByName(stepName).toScala match {
case Some(call: AsyncCallStep[_, _, _]) =>
val effect =
call.transitionFunc
.asInstanceOf[JFunc[Any, TransitionalEffect[Any]]]
.apply(decodeInput(result, call.transitionInputClass))

TransitionalResult(effect)

case Some(any) => throw WorkflowStepNotSupported(any.getClass.getSimpleName)
case None => throw WorkflowStepNotFound(stepName)
}
}
}

0 comments on commit 5c22d14

Please sign in to comment.