Showing results for 
Search instead for 
Did you mean: 

How to use the taskservice ?

Former Member
0 Kudos

I have a usecase ,where I need to retry an operation few times till an expirationTime - if it fails. I thought I can use the taskservice as mentioned in

But I can see that there is no setRetry() in TaskModel.I dont see it is psble to set in the constructor also.

Any idea, how this values can be set - so that I can control programmatically the retry counts and time interval between each retries.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Create a class that implements de.hybris.platform.task.TaskRunner.

You can get the current retry count by calling de.hybris.platform.task.TaskModel.getRetry().

Compare this to a given retry-count and you have your breakup condition.


 public class MyTaskRunner implements TaskRunner<TaskModel> {
     private int maxRetries;
     public void setMaxRetries(final int maxRetries)    {
         this.maxRetries = maxRetries;
     public void run(final TaskService paramTaskService, final TaskModel task) throws RetryLaterException {
         final boolean successful = performOperation();
         if (!successful) {
             if (task.getRetry().intValue() <= maxRetries) {
                 final RetryLaterException ex = new RetryLaterException();
                 ex.setDelay(60 * 60 * 1000);
                 throw ex;
             else {
                 throw new IllegalStateException("giving up after " + task.getRetry() + " retries");