1

I am looking for retry option example for cadence in java, for example I am trying below code snippet but it seems the activity is not re-tried

@ActivityMethod(scheduleToCloseTimeoutSeconds = 30)
@MethodRetry(maximumAttempts = 2, initialIntervalSeconds = 1, expirationSeconds = 30, maximumIntervalSeconds = 30)
String getGreetingContentOverTheWeb(URL url) throws IOException;

for the above activity I am expecting that if it fails should be re-tried automatically, below is how I am calling it

@Override
public String getGreeting(String name) {
    // This is a blocking call that returns only after the activity has completed.
    try {
        String content = activities.getGreetingContentOverTheWeb(new URL("http://localhost:3000/import-map/books"));
        return activities.composeGreeting(content, name);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return activities.composeGreeting("Hello", name);
    
}

Please let me know if I am doing anything incorrect here,

Below is the snapshot from the frontend

enter image description here

Mobina
  • 6,369
  • 2
  • 25
  • 41

1 Answers1

1

From the event history, it looks like the activity is retried. I determined it by looking at the ActivityTaskStarted.attempt field. The number there is equal to the number of retries. So activity executed exactly two times as requested per the specified retry policy.

I know that the name is super confusing as attempts should start from 1 and not from 0. We already fixed this in the temporal.io Cadence fork my team maintains.

Maxim Fateev
  • 6,458
  • 3
  • 20
  • 35
  • Thank You @Maxim Fateev, I re-verified and the re-try option is working as expected, The re-try count starting from zero was confusing but now its clear. – Amit Kumar Agrawal Aug 02 '20 at 03:00
  • Also, few days after I started learning Cadence I realized that there is temporal.io (fork of cadence) with some new features which is also mentioned by you in the above comment, do you recommend Cadence or Temporal going forward for new projects ?. – Amit Kumar Agrawal Aug 02 '20 at 03:04
  • Yes, I recommend using Temporal as it is backed by a company that is focused on the external community. I'm obviously biased as I started the Cadence project and now leading the temporal project as well as the company. See https://stackoverflow.com/questions/61157400/temporal-workflow-vs-cadence-workflow/61281435#61281435 for more about this topic. – Maxim Fateev Aug 02 '20 at 22:13
  • Thanks @Maxim Fateev, can we do re-try from the cadence or temporal fronted also ? for failed workflows ? – Amit Kumar Agrawal Aug 05 '20 at 08:12
  • You can. But you want to code your workflows in a way that they don't fail due to intermittent errors. – Maxim Fateev Aug 06 '20 at 00:37