Skip to content

feat: Step methods with StepEffect - #769

Merged
octonato merged 4 commits into
workflow-step-methodsfrom
octonato/skip-call-result-persistence
Jul 9, 2025
Merged

octonato merged 4 commits into
workflow-step-methodsfrom
octonato/skip-call-result-persistence

Conversation

@octonato

@octonato octonato commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Comment on lines +58 to +71
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +173 to +177
return WorkflowEffects.createEffectBuilder();
}

protected final StepEffect.Builder<S> stepEffects() {
return WorkflowEffects.createStepEffectBuilder();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines -38 to -40
final case class CommandResult(effect: Workflow.Effect[_])

final case class TransitionalResult(effect: Workflow.Effect.TransitionalEffect[_])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Router wrapped types are gone. See comment further down.

Comment on lines +30 to +44
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]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are common types to both effect variants.


}

public interface StepEffect {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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[_]) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines -577 to -578
Workflow<?> instance,
List<StepMethod> stepMethods,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This two should not be here. Moved to WorkflowDescriptor

@octonato
octonato force-pushed the octonato/skip-call-result-persistence branch from a74039e to 45a3e21 Compare July 8, 2025 12:35
@octonato
octonato marked this pull request as ready for review July 8, 2025 12:35
@octonato

octonato commented Jul 8, 2025

Copy link
Copy Markdown
Contributor Author

Now bumped to runtime v1.5.3-780df3f. Should compile and pass the tests.

@aludwiko aludwiko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good

@octonato
octonato merged commit 1ea8f09 into workflow-step-methods Jul 9, 2025
@octonato
octonato deleted the octonato/skip-call-result-persistence branch July 9, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants