Skip to content
Merged
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
51 changes: 50 additions & 1 deletion actions/src/main/java/com/formkiq/module/actions/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public class Action implements DynamodbRecord<Action>, DbKeys {
/** Workflow Step Id. */
@Reflectable
private String workflowStepId;
/** Retry Count. */
@Reflectable
private Integer retryCount;
/** Max Retries. */
@Reflectable
private Integer maxRetries;

/**
* constructor.
Expand Down Expand Up @@ -180,6 +186,8 @@ public Map<String, AttributeValue> getAttributes(final String siteId) {
attrs.put("startDate", AttributeValue.fromS(df.format(this.startDate)));
}

addN(attrs, "retryCount", this.retryCount);
addN(attrs, "maxRetries", this.maxRetries);
addS(attrs, "message", this.message);
addS(attrs, "queueId", this.queueId);
addS(attrs, "workflowId", this.workflowId);
Expand Down Expand Up @@ -216,7 +224,8 @@ public Action getFromAttributes(final String siteId, final Map<String, Attribute
Action record = new Action().documentId(ss(attrs, "documentId")).userId(ss(attrs, "userId"))
.message(ss(attrs, "message")).queueId(ss(attrs, "queueId"))
.workflowId(ss(attrs, "workflowId")).workflowLastStep(ss(attrs, "workflowLastStep"))
.workflowStepId(ss(attrs, "workflowStepId"));
.workflowStepId(ss(attrs, "workflowStepId")).retryCount(toInt(attrs, "retryCount"))
.maxRetries(toInt(attrs, "maxRetries"));

if (attrs.containsKey("status")) {
record.status(ActionStatus.valueOf(ss(attrs, "status")));
Expand Down Expand Up @@ -300,6 +309,26 @@ public Action insertedDate(final Date date) {
return this;
}

/**
* Get Max Retries.
*
* @return {@link Integer}
*/
public Integer maxRetries() {
return maxRetries;
}

/**
* Set Max Retries.
*
* @param count {@link Integer}
* @return {@link Action}
*/
public Action maxRetries(final Integer count) {
this.maxRetries = count;
return this;
}

/**
* Get Action Message.
*
Expand Down Expand Up @@ -410,6 +439,26 @@ public Action queueId(final String id) {
return this;
}

/**
* Get Retry Count.
*
* @return {@link Integer}
*/
public Integer retryCount() {
return retryCount;
}

/**
* Set retry Count.
*
* @param count {@link Integer}
* @return {@link Action}
*/
public Action retryCount(final Integer count) {
this.retryCount = count;
return this;
}

@Override
public String sk() {
if (isEmpty(this.index)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ public enum ActionStatus {
/** Running. */
RUNNING,
/** Skipped. */
SKIPPED;
SKIPPED,
/** Max Retry Reachd. */
MAX_RETRIES_REACHED,
/** Waiting for Retry. */
WAITING_FOR_RETRY
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.formkiq.module.actions.services;

import java.util.List;
import java.util.function.Predicate;
import com.formkiq.module.actions.Action;
import com.formkiq.module.actions.ActionStatus;
Expand All @@ -35,19 +36,19 @@
public class ActionStatusPredicate implements Predicate<Action> {

/** {@link ActionStatus}. */
private ActionStatus status;
private List<ActionStatus> status;

/**
* constructor.
*
* @param actionStatus {@link ActionStatus}
*/
public ActionStatusPredicate(final ActionStatus actionStatus) {
this.status = actionStatus;
public ActionStatusPredicate(final ActionStatus... actionStatus) {
this.status = List.of(actionStatus);
}

@Override
public boolean test(final Action a) {
return this.status.equals(a.status());
return this.status.contains(a.status());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public ActionsServiceDynamoDb(final DynamoDbConnectionBuilder connection,
this.db = new DynamoDbServiceImpl(this.dbClient, documentsTable);
}

private void addKeyIfNotNull(final Map<String, AttributeValueUpdate> updates,
final Map<String, AttributeValue> attrs, final String key) {
if (attrs.get(key) != null) {
updates.put(key, AttributeValueUpdate.builder().value(attrs.get(key)).build());
}
}

private void deleteAction(final String siteId, final Action action) {
String pk = action.pk(siteId);
String sk = action.sk();
Expand Down Expand Up @@ -364,14 +371,10 @@ public void updateActionStatus(final String siteId, final String documentId,
AttributeValueUpdate.builder().value(fromS(df.format(new Date()))).build());
}

if (action.message() != null) {
updates.put("message", AttributeValueUpdate.builder().value(attrs.get("message")).build());
}

if (action.completedDate() != null) {
updates.put("completedDate",
AttributeValueUpdate.builder().value(attrs.get("completedDate")).build());
}
addKeyIfNotNull(updates, attrs, "message");
addKeyIfNotNull(updates, attrs, "retryCount");
addKeyIfNotNull(updates, attrs, "maxRetries");
addKeyIfNotNull(updates, attrs, "completedDate");

for (String index : Arrays.asList(GSI1, GSI2)) {

Expand Down
13 changes: 13 additions & 0 deletions aws-dynamodb/src/main/java/com/formkiq/aws/dynamodb/DbKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ default void addMobject(final Map<String, AttributeValue> map, final String key,
}
}

/**
* Add Number to {@link Map} {@link AttributeValue}.
*
* @param map {@link Map} {@link AttributeValue}
* @param key {@link String}
* @param value {@link Number}
*/
default void addN(final Map<String, AttributeValue> map, final String key, final Number value) {
if (value != null) {
map.put(key, AttributeValue.builder().n(String.valueOf(value)).build());
}
}

/**
* Add Number to {@link Map} {@link AttributeValue}.
*
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ openApiGenerate {
modelPackage.set("com.formkiq.springboot.model")
}

tasks.register("cleanOpenApi") {
tasks.register("buildOpenApi") {
def fileMappings = [
(file("build/ytt/api/api.yaml")) : "openapi-jwt.yaml",
(file("build/ytt/api/api-iam.yaml")) : "openapi-iam.yaml",
Expand Down Expand Up @@ -271,4 +271,4 @@ tasks.register("cleanOpenApi") {
}
}

cleanOpenApi.dependsOn 'yttRenderAll'
buildOpenApi.dependsOn 'yttRenderAll'
8 changes: 8 additions & 0 deletions docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11215,6 +11215,8 @@
- RUNNING
- SKIPPED
- FAILED_RETRY
- MAX_RETRIES_REACHED
- WAITING_FOR_RETRY
DocumentActionType:
type: string
description: Type of the Document Action
Expand All @@ -11240,6 +11242,12 @@
$ref: '#/components/schemas/DocumentActionStatus'
type:
$ref: '#/components/schemas/DocumentActionType'
retryCount:
type: number
description: The number of times this action has already been attempted
maxRetries:
type: number
description: The maximum number of retry attempts allowed for this action
queueId:
type: string
description: Queue Id
Expand Down
8 changes: 8 additions & 0 deletions docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11215,6 +11215,8 @@
- RUNNING
- SKIPPED
- FAILED_RETRY
- MAX_RETRIES_REACHED
- WAITING_FOR_RETRY
DocumentActionType:
type: string
description: Type of the Document Action
Expand All @@ -11240,6 +11242,12 @@
$ref: '#/components/schemas/DocumentActionStatus'
type:
$ref: '#/components/schemas/DocumentActionType'
retryCount:
type: number
description: The number of times this action has already been attempted
maxRetries:
type: number
description: The maximum number of retry attempts allowed for this action
queueId:
type: string
description: Queue Id
Expand Down
8 changes: 8 additions & 0 deletions docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11215,6 +11215,8 @@
- RUNNING
- SKIPPED
- FAILED_RETRY
- MAX_RETRIES_REACHED
- WAITING_FOR_RETRY
DocumentActionType:
type: string
description: Type of the Document Action
Expand All @@ -11240,6 +11242,12 @@
$ref: '#/components/schemas/DocumentActionStatus'
type:
$ref: '#/components/schemas/DocumentActionType'
retryCount:
type: number
description: The number of times this action has already been attempted
maxRetries:
type: number
description: The maximum number of retry attempts allowed for this action
queueId:
type: string
description: Queue Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* MIT License
*
* Copyright (c) 2018 - 2020 FormKiQ
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.testutils.api;

import java.util.function.Predicate;

/**
* {@link Predicate} for {@link ApiHttpResponse} for no error.
*
* @param <T> Type of {@link ApiHttpResponse}
*/
public class ApiHttpResponseOkPredicate<T> implements Predicate<ApiHttpResponse<T>> {
@Override
public boolean test(final ApiHttpResponse<T> apiHttpResponse) {
return !apiHttpResponse.isError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ public class HttpResponseStatus {
/** 404 Response Code. */
private static final int STATUS_404 = 404;
/** 409 Response Code. */
private static final int STATUS_409 = 409;
public static final int STATUS_409 = 409;
/** 429 Response Code. */
private static final int STATUS_429 = 404;
public static final int STATUS_429 = 429;
/** 502 Response Code. */
public static final int STATUS_502 = 502;
/** 429 Response Code. */
public static final int STATUS_503 = 503;
/** 429 Response Code. */
public static final int STATUS_509 = 509;

/**
* Is 2XX Status Code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.formkiq.aws.services.lambda.exceptions.NotFoundException;
import com.formkiq.module.actions.Action;
import com.formkiq.module.actions.ActionStatus;
import com.formkiq.module.actions.services.ActionStatusPredicate;
import com.formkiq.module.actions.services.ActionsNotificationService;
import com.formkiq.module.actions.services.ActionsService;
import com.formkiq.module.lambdaservices.AwsServiceCache;
Expand Down Expand Up @@ -89,7 +90,9 @@ public ApiRequestHandlerResponse post(final ApiGatewayRequestEvent event,
ActionsService service = awsservice.getExtension(ActionsService.class);
List<Action> actions = service.getActions(siteId, documentId);

actions.stream().filter(a -> ActionStatus.RUNNING.equals(a.status()))
actions
.stream().filter(new ActionStatusPredicate(ActionStatus.RUNNING,
ActionStatus.MAX_RETRIES_REACHED, ActionStatus.WAITING_FOR_RETRY))
.forEach(a -> a.status(ActionStatus.FAILED));

int index = IntStream.range(0, actions.size()).map(i -> actions.size() - 1 - i)
Expand Down
Loading
Loading