Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public TryTaskCatchBuilder<T> retry(Consumer<RetryPolicyBuilder> consumer) {
return this;
}

public TryTaskCatchBuilder<T> retry(String reference) {
this.tryTaskCatch.setRetry(new Retry().withRetryPolicyReference(reference));
return this;
}

public TryTaskCatchBuilder<T> errorsWith(Consumer<CatchErrorsBuilder> consumer) {
final CatchErrorsBuilder catchErrorsBuilder = new CatchErrorsBuilder();
consumer.accept(catchErrorsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
import io.serverlessworkflow.api.types.ErrorDetails;
import io.serverlessworkflow.api.types.ErrorTitle;
import io.serverlessworkflow.api.types.ErrorType;
import io.serverlessworkflow.api.types.RetryPolicy;
import io.serverlessworkflow.api.types.UriTemplate;
import io.serverlessworkflow.api.types.Use;
import io.serverlessworkflow.api.types.UseAuthentications;
import io.serverlessworkflow.api.types.UseErrors;
import io.serverlessworkflow.api.types.UseRetries;
import io.serverlessworkflow.fluent.spec.BaseTryTaskBuilder.RetryPolicyBuilder;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class UseBuilder {
Expand Down Expand Up @@ -66,6 +71,17 @@ public UseBuilder errors(Consumer<UseErrorsBuilder> errorsConsumer) {
return this;
}

public UseBuilder retries(Consumer<UseRetriesBuilder> retriesConsumer) {
final UseRetriesBuilder retriesBuilder = new UseRetriesBuilder();
retriesConsumer.accept(retriesBuilder);
final UseRetries built = retriesBuilder.build();
if (this.use.getRetries() == null) {
this.use.setRetries(new UseRetries());
}
this.use.getRetries().getAdditionalProperties().putAll(built.getAdditionalProperties());
return this;
}
Comment on lines +74 to +83

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 map is never null when instantiated by UsesRetries


public Use build() {
return use;
}
Expand Down Expand Up @@ -132,4 +148,23 @@ public Error build() {
return error;
}
}

public static final class UseRetriesBuilder {
private final Map<String, RetryPolicy> retries = new LinkedHashMap<>();

UseRetriesBuilder() {}

public UseRetriesBuilder retry(String name, Consumer<RetryPolicyBuilder> configurer) {
final RetryPolicyBuilder policyBuilder = new RetryPolicyBuilder();
configurer.accept(policyBuilder);
this.retries.put(name, policyBuilder.build());
return this;
}

public UseRetries build() {
final UseRetries useRetries = new UseRetries();
useRetries.getAdditionalProperties().putAll(this.retries);
return useRetries;
}
Comment on lines +164 to +168

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.

here too

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ default SELF query(String name, String value) {
return self();
}

default SELF redirect(boolean redirect) {
steps().add(c -> c.redirect(redirect));
return self();
}

default void accept(CallHttpTaskFluent<?> b) {
for (var s : steps()) {
s.accept(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.serverlessworkflow.fluent.spec.dsl;

import io.serverlessworkflow.fluent.spec.DurationInlineBuilder;
import io.serverlessworkflow.fluent.spec.TryTaskBuilder;
import io.serverlessworkflow.fluent.spec.configurers.RetryConfigurer;
import java.util.LinkedList;
Expand Down Expand Up @@ -51,11 +52,49 @@ public RetrySpec limit(Consumer<TryTaskBuilder.RetryLimitBuilder> retry) {
return this;
}

public RetrySpec delay(String expression) {
steps.add(r -> r.delay(expression));
return this;
}

/**
* Configures an inline delay using a duration builder.
*
* @see #delay(String)
*/
public RetrySpec delay(Consumer<DurationInlineBuilder> duration) {
steps.add(r -> r.delay(duration));
return this;
}
Comment thread
matheusandre1 marked this conversation as resolved.

public RetrySpec backoff(Consumer<TryTaskBuilder.BackoffBuilder> backoff) {
steps.add(r -> r.backoff(backoff));
return this;
}

/**
* Configures exponential backoff with identifier "e" and a default factor of "1.5". This is a
* convenience shortcut; for full control use {@link #backoff(Consumer)}.
*
* @return this spec
*/
public RetrySpec backoffExponential() {
steps.add(r -> r.backoff(b -> b.exponential("e", "1.5")));
return this;
}

/**
* Configures constant backoff with identifier "c" and a default delay of "10" (units unspecified
* by the spec; typically milliseconds). This is a convenience shortcut; for full control use
* {@link #backoff(Consumer)}.
*
* @return this spec
*/
public RetrySpec backoffConstant() {
steps.add(r -> r.backoff(b -> b.constant("c", "10")));
return this;
}
Comment thread
matheusandre1 marked this conversation as resolved.
Comment thread
matheusandre1 marked this conversation as resolved.

public RetrySpec jitter(Consumer<TryTaskBuilder.RetryPolicyJitterBuilder> jitter) {
steps.add(r -> r.jitter(jitter));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public TryCatchSpec errors(Consumer<TryTaskBuilder.CatchErrorsBuilder> errors) {
return this;
}

public TryCatchSpec as(String errorVarName) {
steps.add(t -> t.as(errorVarName));
return this;
}

public TryCatchSpec retry(String reference) {
steps.add(t -> t.retry(reference));
return this;
}

public RetrySpec retry() {
return retry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public UseSpec errors(Consumer<UseBuilder.UseErrorsBuilder> errorsConsumer) {
return this;
}

public UseSpec retries(Consumer<UseBuilder.UseRetriesBuilder> retriesConsumer) {
steps.add(u -> u.retries(retriesConsumer));
return this;
}

@Override
public void accept(UseBuilder useBuilder) {
steps.forEach(step -> step.accept(useBuilder));
Expand Down
Loading
Loading