Skip to content

Commit bf57509

Browse files
committed
Added max retries / waiting for retry (#438)
1 parent db1c5b6 commit bf57509

File tree

23 files changed

+413
-101
lines changed

23 files changed

+413
-101
lines changed

actions/src/main/java/com/formkiq/module/actions/Action.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public class Action implements DynamodbRecord<Action>, DbKeys {
9191
/** Workflow Step Id. */
9292
@Reflectable
9393
private String workflowStepId;
94+
/** Retry Count. */
95+
@Reflectable
96+
private Integer retryCount;
97+
/** Max Retries. */
98+
@Reflectable
99+
private Integer maxRetries;
94100

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

189+
addN(attrs, "retryCount", this.retryCount);
190+
addN(attrs, "maxRetries", this.maxRetries);
183191
addS(attrs, "message", this.message);
184192
addS(attrs, "queueId", this.queueId);
185193
addS(attrs, "workflowId", this.workflowId);
@@ -216,7 +224,8 @@ public Action getFromAttributes(final String siteId, final Map<String, Attribute
216224
Action record = new Action().documentId(ss(attrs, "documentId")).userId(ss(attrs, "userId"))
217225
.message(ss(attrs, "message")).queueId(ss(attrs, "queueId"))
218226
.workflowId(ss(attrs, "workflowId")).workflowLastStep(ss(attrs, "workflowLastStep"))
219-
.workflowStepId(ss(attrs, "workflowStepId"));
227+
.workflowStepId(ss(attrs, "workflowStepId")).retryCount(toInt(attrs, "retryCount"))
228+
.maxRetries(toInt(attrs, "maxRetries"));
220229

221230
if (attrs.containsKey("status")) {
222231
record.status(ActionStatus.valueOf(ss(attrs, "status")));
@@ -300,6 +309,26 @@ public Action insertedDate(final Date date) {
300309
return this;
301310
}
302311

312+
/**
313+
* Get Max Retries.
314+
*
315+
* @return {@link Integer}
316+
*/
317+
public Integer maxRetries() {
318+
return maxRetries;
319+
}
320+
321+
/**
322+
* Set Max Retries.
323+
*
324+
* @param count {@link Integer}
325+
* @return {@link Action}
326+
*/
327+
public Action maxRetries(final Integer count) {
328+
this.maxRetries = count;
329+
return this;
330+
}
331+
303332
/**
304333
* Get Action Message.
305334
*
@@ -410,6 +439,26 @@ public Action queueId(final String id) {
410439
return this;
411440
}
412441

442+
/**
443+
* Get Retry Count.
444+
*
445+
* @return {@link Integer}
446+
*/
447+
public Integer retryCount() {
448+
return retryCount;
449+
}
450+
451+
/**
452+
* Set retry Count.
453+
*
454+
* @param count {@link Integer}
455+
* @return {@link Action}
456+
*/
457+
public Action retryCount(final Integer count) {
458+
this.retryCount = count;
459+
return this;
460+
}
461+
413462
@Override
414463
public String sk() {
415464
if (isEmpty(this.index)) {

actions/src/main/java/com/formkiq/module/actions/ActionStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ public enum ActionStatus {
4242
/** Running. */
4343
RUNNING,
4444
/** Skipped. */
45-
SKIPPED;
45+
SKIPPED,
46+
/** Max Retry Reachd. */
47+
MAX_RETRIES_REACHED,
48+
/** Waiting for Retry. */
49+
WAITING_FOR_RETRY
4650
}

actions/src/main/java/com/formkiq/module/actions/services/ActionStatusPredicate.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.formkiq.module.actions.services;
2525

26+
import java.util.List;
2627
import java.util.function.Predicate;
2728
import com.formkiq.module.actions.Action;
2829
import com.formkiq.module.actions.ActionStatus;
@@ -35,19 +36,19 @@
3536
public class ActionStatusPredicate implements Predicate<Action> {
3637

3738
/** {@link ActionStatus}. */
38-
private ActionStatus status;
39+
private List<ActionStatus> status;
3940

4041
/**
4142
* constructor.
4243
*
4344
* @param actionStatus {@link ActionStatus}
4445
*/
45-
public ActionStatusPredicate(final ActionStatus actionStatus) {
46-
this.status = actionStatus;
46+
public ActionStatusPredicate(final ActionStatus... actionStatus) {
47+
this.status = List.of(actionStatus);
4748
}
4849

4950
@Override
5051
public boolean test(final Action a) {
51-
return this.status.equals(a.status());
52+
return this.status.contains(a.status());
5253
}
5354
}

actions/src/main/java/com/formkiq/module/actions/services/ActionsServiceDynamoDb.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public ActionsServiceDynamoDb(final DynamoDbConnectionBuilder connection,
9898
this.db = new DynamoDbServiceImpl(this.dbClient, documentsTable);
9999
}
100100

101+
private void addKeyIfNotNull(final Map<String, AttributeValueUpdate> updates,
102+
final Map<String, AttributeValue> attrs, final String key) {
103+
if (attrs.get(key) != null) {
104+
updates.put(key, AttributeValueUpdate.builder().value(attrs.get(key)).build());
105+
}
106+
}
107+
101108
private void deleteAction(final String siteId, final Action action) {
102109
String pk = action.pk(siteId);
103110
String sk = action.sk();
@@ -364,14 +371,10 @@ public void updateActionStatus(final String siteId, final String documentId,
364371
AttributeValueUpdate.builder().value(fromS(df.format(new Date()))).build());
365372
}
366373

367-
if (action.message() != null) {
368-
updates.put("message", AttributeValueUpdate.builder().value(attrs.get("message")).build());
369-
}
370-
371-
if (action.completedDate() != null) {
372-
updates.put("completedDate",
373-
AttributeValueUpdate.builder().value(attrs.get("completedDate")).build());
374-
}
374+
addKeyIfNotNull(updates, attrs, "message");
375+
addKeyIfNotNull(updates, attrs, "retryCount");
376+
addKeyIfNotNull(updates, attrs, "maxRetries");
377+
addKeyIfNotNull(updates, attrs, "completedDate");
375378

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

aws-dynamodb/src/main/java/com/formkiq/aws/dynamodb/DbKeys.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ default void addMobject(final Map<String, AttributeValue> map, final String key,
165165
}
166166
}
167167

168+
/**
169+
* Add Number to {@link Map} {@link AttributeValue}.
170+
*
171+
* @param map {@link Map} {@link AttributeValue}
172+
* @param key {@link String}
173+
* @param value {@link Number}
174+
*/
175+
default void addN(final Map<String, AttributeValue> map, final String key, final Number value) {
176+
if (value != null) {
177+
map.put(key, AttributeValue.builder().n(String.valueOf(value)).build());
178+
}
179+
}
180+
168181
/**
169182
* Add Number to {@link Map} {@link AttributeValue}.
170183
*

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ openApiGenerate {
226226
modelPackage.set("com.formkiq.springboot.model")
227227
}
228228

229-
tasks.register("cleanOpenApi") {
229+
tasks.register("buildOpenApi") {
230230
def fileMappings = [
231231
(file("build/ytt/api/api.yaml")) : "openapi-jwt.yaml",
232232
(file("build/ytt/api/api-iam.yaml")) : "openapi-iam.yaml",
@@ -271,4 +271,4 @@ tasks.register("cleanOpenApi") {
271271
}
272272
}
273273

274-
cleanOpenApi.dependsOn 'yttRenderAll'
274+
buildOpenApi.dependsOn 'yttRenderAll'

docs/openapi/openapi-iam.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11215,6 +11215,8 @@
1121511215
- RUNNING
1121611216
- SKIPPED
1121711217
- FAILED_RETRY
11218+
- MAX_RETRIES_REACHED
11219+
- WAITING_FOR_RETRY
1121811220
DocumentActionType:
1121911221
type: string
1122011222
description: Type of the Document Action
@@ -11240,6 +11242,12 @@
1124011242
$ref: '#/components/schemas/DocumentActionStatus'
1124111243
type:
1124211244
$ref: '#/components/schemas/DocumentActionType'
11245+
retryCount:
11246+
type: number
11247+
description: The number of times this action has already been attempted
11248+
maxRetries:
11249+
type: number
11250+
description: The maximum number of retry attempts allowed for this action
1124311251
queueId:
1124411252
type: string
1124511253
description: Queue Id

docs/openapi/openapi-jwt.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11215,6 +11215,8 @@
1121511215
- RUNNING
1121611216
- SKIPPED
1121711217
- FAILED_RETRY
11218+
- MAX_RETRIES_REACHED
11219+
- WAITING_FOR_RETRY
1121811220
DocumentActionType:
1121911221
type: string
1122011222
description: Type of the Document Action
@@ -11240,6 +11242,12 @@
1124011242
$ref: '#/components/schemas/DocumentActionStatus'
1124111243
type:
1124211244
$ref: '#/components/schemas/DocumentActionType'
11245+
retryCount:
11246+
type: number
11247+
description: The number of times this action has already been attempted
11248+
maxRetries:
11249+
type: number
11250+
description: The maximum number of retry attempts allowed for this action
1124311251
queueId:
1124411252
type: string
1124511253
description: Queue Id

docs/openapi/openapi-key.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11215,6 +11215,8 @@
1121511215
- RUNNING
1121611216
- SKIPPED
1121711217
- FAILED_RETRY
11218+
- MAX_RETRIES_REACHED
11219+
- WAITING_FOR_RETRY
1121811220
DocumentActionType:
1121911221
type: string
1122011222
description: Type of the Document Action
@@ -11240,6 +11242,12 @@
1124011242
$ref: '#/components/schemas/DocumentActionStatus'
1124111243
type:
1124211244
$ref: '#/components/schemas/DocumentActionType'
11245+
retryCount:
11246+
type: number
11247+
description: The number of times this action has already been attempted
11248+
maxRetries:
11249+
type: number
11250+
description: The maximum number of retry attempts allowed for this action
1124311251
queueId:
1124411252
type: string
1124511253
description: Queue Id
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 - 2020 FormKiQ
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.formkiq.testutils.api;
25+
26+
import java.util.function.Predicate;
27+
28+
/**
29+
* {@link Predicate} for {@link ApiHttpResponse} for no error.
30+
*
31+
* @param <T> Type of {@link ApiHttpResponse}
32+
*/
33+
public class ApiHttpResponseOkPredicate<T> implements Predicate<ApiHttpResponse<T>> {
34+
@Override
35+
public boolean test(final ApiHttpResponse<T> apiHttpResponse) {
36+
return !apiHttpResponse.isError();
37+
}
38+
}

0 commit comments

Comments
 (0)