Skip to content

Commit

Permalink
feat: import of maxRetries methods is no longer required (#2019)
Browse files Browse the repository at this point in the history
* feat: import of maxRetries methods is no longer required

* fmt
  • Loading branch information
aludwiko authored Feb 7, 2024
1 parent e796eda commit 77fcbdc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static io.grpc.Status.Code.NOT_FOUND;
import static java.time.Duration.ofHours;
import static java.time.Duration.ofSeconds;
import static kalix.javasdk.workflow.AbstractWorkflow.RecoverStrategy.maxRetries;

// This class was initially generated based on the .proto definition by Kalix tooling.
// This is the implementation for the Workflow Service described in your com/example/transfer/wallet_api.proto file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import static com.example.transfer.TransferState.TransferStatus.WITHDRAW_SUCCEED;
import static java.time.Duration.ofHours;
import static java.time.Duration.ofSeconds;
import static kalix.javasdk.workflow.AbstractWorkflow.RecoverStrategy.maxRetries;

@TypeId("transfer")
@Id("transferId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,16 @@ public StepConfig(String stepName, Optional<Duration> timeout, Optional<RecoverS
}
}

/**
* Starts defining a recover strategy for the workflow or a specific step.
*
* @param maxRetries number of retries before giving up.
* @return MaxRetries strategy.
*/
public MaxRetries maxRetries(int maxRetries) {
return RecoverStrategy.maxRetries(maxRetries);
}

public static class RecoverStrategy<T> {

public final int maxRetries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.concurrent.CompletableFuture;

import static java.time.Duration.ofSeconds;
import static kalix.javasdk.workflow.AbstractWorkflow.RecoverStrategy.maxRetries;

@Id("workflowId")
@TypeId("workflow-with-recover-strategy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kalix.scalasdk.DeferredCall
import kalix.scalasdk.Metadata
import kalix.scalasdk.impl.workflow.WorkflowEffectImpl
import kalix.scalasdk.timer.TimerScheduler
import kalix.scalasdk.workflow.AbstractWorkflow.RecoverStrategy.MaxRetries

object AbstractWorkflow {

Expand Down Expand Up @@ -225,7 +226,7 @@ object AbstractWorkflow {
private var _workflowTimeout: Option[FiniteDuration] = None,
private var _failoverStepName: Option[String] = None,
private var _failoverStepInput: Option[Any] = None,
private var _failoverMaxRetries: Option[RecoverStrategy.MaxRetries] = None,
private var _failoverMaxRetries: Option[MaxRetries] = None,
private var _stepTimeout: Option[FiniteDuration] = None,
private var _stepRecoverStrategy: Option[AbstractWorkflow.RecoverStrategy[_]] = None) {

Expand Down Expand Up @@ -287,7 +288,7 @@ object AbstractWorkflow {
* @param maxRetries
* A recovery strategy for failover step.
*/
def failoverTo(stepName: String, maxRetries: RecoverStrategy.MaxRetries): AbstractWorkflow.WorkflowDef[S] = {
def failoverTo(stepName: String, maxRetries: MaxRetries): AbstractWorkflow.WorkflowDef[S] = {
if (stepName == null) throw new IllegalArgumentException("Step name cannot be null")
if (maxRetries == null) throw new IllegalArgumentException("Max retries cannot be null")
this._failoverStepName = Option(stepName)
Expand All @@ -306,10 +307,7 @@ object AbstractWorkflow {
* @param maxRetries
* A recovery strategy for failover step.
*/
def failoverTo[I](
stepName: String,
stepInput: I,
maxRetries: RecoverStrategy.MaxRetries): AbstractWorkflow.WorkflowDef[S] = {
def failoverTo[I](stepName: String, stepInput: I, maxRetries: MaxRetries): AbstractWorkflow.WorkflowDef[S] = {
if (stepName == null) throw new IllegalArgumentException("Step name cannot be null")
if (stepInput == null) throw new IllegalArgumentException("Step input cannot be null")
if (maxRetries == null) throw new IllegalArgumentException("Max retries cannot be null")
Expand Down Expand Up @@ -351,7 +349,7 @@ object AbstractWorkflow {

def failoverStepInput: Option[_] = _failoverStepInput

def failoverMaxRetries: Option[RecoverStrategy.MaxRetries] = _failoverMaxRetries
def failoverMaxRetries: Option[MaxRetries] = _failoverMaxRetries
}

sealed trait Step {
Expand Down Expand Up @@ -410,6 +408,13 @@ object AbstractWorkflow {
timeout: Option[FiniteDuration],
recoverStrategy: Option[AbstractWorkflow.RecoverStrategy[_]]) {}

/**
* Starts defining a recover strategy for the workflow or a specific step.
* @param maxRetries
* number of retries before giving up.
*/
def maxRetries(maxRetries: Int): MaxRetries = RecoverStrategy.maxRetries(maxRetries)

object RecoverStrategy {

/**
Expand All @@ -436,7 +441,7 @@ object AbstractWorkflow {
* Set the number of retires for a failed step, `maxRetries` equals 0 means that the step won't retry in case of
* failure.
*/
def maxRetries(maxRetries: Int): RecoverStrategy.MaxRetries = RecoverStrategy.MaxRetries(maxRetries)
def maxRetries(maxRetries: Int): MaxRetries = MaxRetries(maxRetries)

/**
* In case of a step failure don't retry but transition to a given step name.
Expand Down

0 comments on commit 77fcbdc

Please sign in to comment.