Repository navigation
feat: Step methods with StepEffect - #769
Conversation
| private StepEffect withdraw() { | ||
|
|
||
| var fromWallet = currentState().transfer().from(); | ||
| var amount = currentState().transfer().amount(); | ||
|
|
||
| componentClient | ||
| .forKeyValueEntity(fromWallet) | ||
| .method(WalletEntity::withdraw) | ||
| .invoke(amount); | ||
|
|
||
| var state = currentState().withLastStep("withdrawn").asAccepted(); | ||
| return stepEffects() | ||
| .updateState(state) | ||
| .transitionTo("deposit"); // FIXME: use method ref and make it typed |
There was a problem hiding this comment.
The WorkflowTests use this workflow and the tests are passing!!
For now, it only works because the methods receive 0 param and all the info we need is in the state already.
On a next phase, I want to pass methodRefs to the transitionTo method and make it fully typed.
| return WorkflowEffects.createEffectBuilder(); | ||
| } | ||
|
|
||
| protected final StepEffect.Builder<S> stepEffects() { | ||
| return WorkflowEffects.createStepEffectBuilder(); |
There was a problem hiding this comment.
There are two types of Effects now.
So I added them under WorkflowEffects, but it turns out that accessing nested scala objects from java doesn't work. So hence this builder methods now.
| } | ||
|
|
||
| @nowarn("msg=deprecated") // DeleteState deprecated but must be in here | ||
| private def toSpiCommandEffect(effect: Workflow.Effect[_]): SpiWorkflow.CommandEffect = { |
There was a problem hiding this comment.
I move all the conversion to SPI types under the router. I think we were complicating ourselves by having SDK types, router intermediary types and SPI types. We should go from SDK to SPI directly.
| final case class CommandResult(effect: Workflow.Effect[_]) | ||
|
|
||
| final case class TransitionalResult(effect: Workflow.Effect.TransitionalEffect[_]) |
There was a problem hiding this comment.
Router wrapped types are gone. See comment further down.
| case class StepTransition[I](stepName: String, input: Option[I]) extends Transition | ||
|
|
||
| object Pause extends Transition | ||
|
|
||
| object NoTransition extends Transition | ||
|
|
||
| object End extends Transition | ||
|
|
||
| object Delete extends Transition | ||
|
|
||
| sealed trait Persistence[+S] | ||
|
|
||
| final case class UpdateState[S](newState: S) extends Persistence[S] | ||
|
|
||
| case object NoPersistence extends Persistence[Nothing] |
There was a problem hiding this comment.
Those are common types to both effect variants.
|
|
||
| } | ||
|
|
||
| public interface StepEffect { |
There was a problem hiding this comment.
I still want to consider if we should call this a TransitionalEffect.
I'm not yet fully convinced by this name. We do make a call to a method, but the outcome is looking more like a transition.
You transition the state to a new state and then you move to the next step.
Anyway, we are not in a hurry and we can let it sink a little more.
|
|
||
| import scala.jdk.CollectionConverters.ListHasAsScala | ||
|
|
||
| class WorkflowDescriptor(workflow: Workflow[_]) { |
There was a problem hiding this comment.
I wasn't happy with the workflow and list of step inside the Settings, so moved it to this descriptor.
Settings should be only about timeout and recovery.
| Workflow<?> instance, | ||
| List<StepMethod> stepMethods, |
There was a problem hiding this comment.
This two should not be here. Moved to WorkflowDescriptor
a74039e to
45a3e21
Compare
|
Now bumped to runtime v1.5.3-780df3f. Should compile and pass the tests. |
No description provided.