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

Using @Retryable in @Service at method level not working with @Scheduled method in another class #243

Open
amolkumar18 opened this issue Jun 1, 2021 · 11 comments

Comments

@amolkumar18
Copy link

Using @retryable in @service at method level which is going to retry 3 times by default if get any exception and @recover responsible to sa error count in postgres database table.
I have seperate class for @EnableScheduling with scheduled cron run every four hours which will going to process these failed cases by querying this postgres table.
When aplication starts and failed for the service class within the method annotated with @retryable able to save record in db but when trying through scheduler it's not updating the failure count in database

Originally posted by @amolkumar18 in #94 (comment)

@garyrussell
Copy link
Contributor

You need to show code, configuration and version information or, preferably, a small, complete, example that exhibits the behavior.

@amolkumar18
Copy link
Author

Ok. Give me sometime, will get back to you on this with artifact's n sample code,

@amolkumar18
Copy link
Author

amolkumar18 commented Jun 1, 2021

@Service
public class MigrationStepOne {

@Autowired 
private Service1 Service1;

@Retryable(backoff = @Backoff(5000), value = {Exception.class})
public String stepOneProcessing(CustomerMigrationStep cms){
try{
String str = "Hello" + 4/0;
return "successful";
}catch(Exception e){
throw e;
}
}

@Recover
public String recover(Exception e, CustomerMigrationStep cms){
CustomerMigrationStep cmss = null;
cmss.setFailureCount(cms.getFailedCount() + 3);
cms = cmss;
service1.saveFailedCount(cms);
}
}
@Component
@EnableScheduling
public class Retry scheduler {

@Autowired
private CustomerMigrationStepRepo repo;

@scheduled(cron = "0 0 4,8 0 0 0)
public void retryingMethod(){
List<CustomerMigrationStep> list = repo.findAllFailedCountCases();
for ( CustomerMigrationStep step: list){
CallClassXyz method which internally calls the method retryingMethod() of service class MigrationStepOne
}
}
}

@amolkumar18
Copy link
Author

org.springframework.boot spring-boot-starter-parent 2.5.0 pom org.springframework.retry spring-retry 1.3.1

@amolkumar18
Copy link
Author

amolkumar18 commented Jun 1, 2021

public class Service1{

@Autowired
private CustomerMigrationStepRepo repo;

public void saveFailedCount(CustomerMigrationStep cms){
repo.saveAndFlush(cms);
}
}

@amolkumar18
Copy link
Author

amolkumar18 commented Jun 1, 2021

Table entry
CustId. failureCount
1 3
Ideally after scheduler call it should update to 6 but it's not happening. Count remains 3 only.

@amolkumar18
Copy link
Author

Do we expecting any other information ??

@garyrussell
Copy link
Contributor

Please learn how to use GItHub markdown to format code.

This code makes no sense to me

CustomerMigrationStep cmss = null;
cmss.setFailureCount(cms.getFailedCount() + 3);

The second line will throw a NullPointerException.

@kumarvinothjoseph
Copy link

Spring Boot Starter - 2.1.7.RELEASE, Spring-aop - 5.1.9.RELEASE, spring-retry -1.2.4.RELEASE,

@EnableRetry in SpringBootApplication class

My Business Logic class is annotated with @component And one of the method annotated with @scheduled(cron="") & @retryable(value = Exception.class, maxAttempts = 3, backoff= @backoff(delay = 1000))

Here Scheduling is working But Retryable is not working. Could you please help on this ?

@samirm
Copy link

samirm commented Feb 1, 2023

same issue here

@artembilan
Copy link
Member

@samirm ,
any chances you can share with us a code which may reproduce the issue?
The simple Spring Boot project to play with would be great.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants