on 11-12-2014 3:44 PM
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 https://wiki.hybris.com/pages/viewpage.action?title=task+-+Technical+Guide&spaceKey=release5
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.
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.
Example:
public class MyTaskRunner implements TaskRunner<TaskModel> {
private int maxRetries;
@Required
public void setMaxRetries(final int maxRetries) {
this.maxRetries = maxRetries;
}
@Override
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");
}
}
}
[...]
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.