Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry / File State Storage #385

Merged
merged 24 commits into from
May 17, 2023

Conversation

vaibhav-db
Copy link
Contributor

refactor retry handler

vaibhav-db and others added 8 commits February 24, 2023 13:15
…daptive card

Merge in SYMPHONYP/symphony-java-toolkit from feature/SYMPHONYP-939-ms-teams-spring-bot-retry-messages to spring-bot-master-db

* commit '3f2fec632e13056b0fec79bffe62697fec0e4913':
  SYMPHONYP-940 MS Teams feature to submit the adaptive card
Merge in SYMPHONYP/symphony-java-toolkit from feature/SYMPHONYP-939-ms-teams-spring-bot-retry-messages to spring-bot-master-db

* commit '3e4b60cbfa4318e45122d113b408aec181c8bf98':
  review comments changes done.
  added testcases for Message Retry.
  SYMPHONYP-939 implements review comments
  SYMPHONYP-940 refactor retry handler
  fixing formatting
  Adding roadmap
  Update LICENSE
  setting copyright name
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 27, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@pankajpkhandelwal-db pankajpkhandelwal-db self-assigned this Mar 27, 2023
@@ -62,7 +61,7 @@ public class TeamsResponseHandler implements ResponseHandler, ApplicationContext
protected ThymeleafTemplateProvider displayTemplater;
protected TeamsStateStorage teamsState;
protected TeamsConversations teamsConversations;
protected MessageRetryHandler messageRetryHandler;
protected MessageRetryHandler retryHandler;
Copy link
Member

Choose a reason for hiding this comment

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

can we not have retryHandler in a subclass? e.g. RetryingTeamsResponseHandler?

Copy link
Contributor

Choose a reason for hiding this comment

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

Changes done as per review comments

@@ -142,7 +141,7 @@ protected TemplateType getTemplateType(WorkResponse wr) {
TemplateType tt;
if (displayTemplater.hasTemplate(wr)) {
tt = TemplateType.THYMELEAF;
} else if (workTemplater.hasTemplate(wr)) {
} else if (workTemplater.hasTemplate(wr) || AdaptiveCardPassthrough.isAdaptiveCard(wr)) {
Copy link
Member

Choose a reason for hiding this comment

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

it's odd that this has changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Rob,

We have usecase where we wanted to send adaptive card as passthrough like user send Adaptive card json as string input parameter and bot will send this adaptive card to ms teams channel.

@@ -274,7 +251,7 @@ public void retryMessage() {
int messageCount = 0;

Optional<MessageRetry> opt;
while ((opt = messageRetryHandler.get()).isPresent()) {
while ((opt = retryHandler.get()).isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

please make sure we have code coverage of this.

abhishekdahiya-db and others added 5 commits March 31, 2023 15:20
Merge in SYMPHONYP/symphony-java-toolkit from bugfix/SYMPHONYP-946-History-Api-bug-fix to spring-bot-master-db

* commit '18d766fd56c9bb561b2de3179c75cd57fae5e3eb':
  bug fix implemented.
@robmoffat robmoffat changed the title Spring bot master db Retry / File State Storage Apr 3, 2023
…andler refactor code

Merge in SYMPHONYP/symphony-java-toolkit from feature/SYMPHONYP-947-teams-spring-bot-retry-handler-refactor-code to spring-bot-master-db

* commit '320488b2b314041fab0498f244763a1c2250973c':
  refactor retry message handler
  refactor retry message handler
  refactor retry message handler
  refactor retry message handler
  refactor retry message handler
  refactor retry message handler
@@ -72,6 +72,28 @@ public void testStoreWithTagDates() throws IOException {
Assertions.assertEquals(2, hoover(tss.retrieve(tagList4, false)).size());
}

@Test
public void testSlashStoreWithMultTags() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

testFilenamesWithSlash

tss.store("thefile/thefile", tags1, somedata);
tss.store("thefile/theotherfile", tags2, somedata);

Assertions.assertEquals(1, hoover(tss.retrieve(tagList1, false)).size());
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't you also check you can retrieve the other file as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.. I will add other file also.


public class InMemoryRetryingActivityHandler extends AbstractRetryingActivityHandler {

private Queue<MessageRetry> queue = new ConcurrentLinkedQueue<>();
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have already tried this, it was not working. As per our requirement if exception occurred we need to wait for Retry-After then try retry.

Copy link
Member

Choose a reason for hiding this comment

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

What didn't work about it? Is it the lack of delay? I am looking at this code from the SO page:

public CompletableFuture<Result> executeActionAsync() {
    CompletableFuture<Result> f=executeMycustomActionHere();
    for(int i=0; i<MAX_RETRIES; i++) {
        f=f.thenApply(CompletableFuture::completedFuture)
           .exceptionally(t -> executeMycustomActionHere())
           .thenCompose(Function.identity());
    }
    return f;
}

Copy link
Member

Choose a reason for hiding this comment

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

should not be too hard to add a delay on the .exceptionally() line, if that is the problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No our requirement is to wait for Retry-Afer time, but we can't add the sleep or wait as it will wait the thread. we have implemented similar only inserted data into queue. and added cron job to resent the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we just don't want to used Thread.sleep(ra); in code. As it will keep the current thread on wait. :)

We can connect on Monday, I will explain you.
I am learning the CompletableFuture :)

Copy link
Member

Choose a reason for hiding this comment

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

argh you're right!! 😦

How about this: deutschebank#1

I actually wrote a test here - well, changed your InMemoryRetryingActivityHandlerTest to see if this actually worked.

Test passes but maybe you have more to add..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Rob,

Testcase only pass, if we have for (int i = 0; i < teamsRetryCount; i++) { for loop in code. But in our case, if exception occurred we simply insert that record in in-memory queue.
Here we have to check the how to write testcase around schedule also.

Copy link
Member

Choose a reason for hiding this comment

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

Hi, we can wait until Wednesday to talk about this or we can maybe have a call a bit sooner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Rob, we will connect tomorrow. Completely overload with teams.
I have tried CompletableFuture.delayedExecutor(ra, TimeUnit.MILLISECONDS) but it is in java 9, so we can't go for it.
Alternate solution i found as scheduler.
https://stackoverflow.com/questions/58707689/is-it-possible-to-schedule-a-completablefuture

Copy link
Member

@robmoffat robmoffat left a comment

Choose a reason for hiding this comment

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

looks good to me

@robmoffat robmoffat merged commit 4280e2f into finos:spring-bot-master May 17, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants