use of org.camunda.bpm.engine.impl.calendar.DurationHelper in project camunda-bpm-platform by camunda.
the class ParseUtil method parseRetryIntervals.
public static FailedJobRetryConfiguration parseRetryIntervals(String retryIntervals) {
if (retryIntervals != null && !retryIntervals.isEmpty()) {
if (StringUtil.isExpression(retryIntervals)) {
ExpressionManager expressionManager = Context.getProcessEngineConfiguration().getExpressionManager();
Expression expression = expressionManager.createExpression(retryIntervals);
return new FailedJobRetryConfiguration(expression);
}
String[] intervals = StringUtil.split(retryIntervals, ",");
int retries = intervals.length + 1;
if (intervals.length == 1) {
try {
DurationHelper durationHelper = new DurationHelper(intervals[0]);
if (durationHelper.isRepeat()) {
retries = durationHelper.getTimes();
}
} catch (Exception e) {
LOG.logParsingRetryIntervals(intervals[0], e);
return null;
}
}
return new FailedJobRetryConfiguration(retries, Arrays.asList(intervals));
} else {
return null;
}
}
use of org.camunda.bpm.engine.impl.calendar.DurationHelper in project camunda-bpm-platform by camunda.
the class DurationHelperTest method shouldNotExceedNumberPeriods.
@Test
public void shouldNotExceedNumberPeriods() throws Exception {
ClockUtil.setCurrentTime(parse("19700101-00:00:00"));
DurationHelper dh = new DurationHelper("R2/1970-01-01T00:00:00/1970-01-01T00:00:10");
ClockUtil.setCurrentTime(parse("19700101-00:00:15"));
assertEquals(parse("19700101-00:00:20"), dh.getDateAfter());
ClockUtil.setCurrentTime(parse("19700101-00:00:30"));
assertNull(dh.getDateAfter());
}
use of org.camunda.bpm.engine.impl.calendar.DurationHelper in project camunda-bpm-platform by camunda.
the class DefaultJobRetryCmd method executeCustomStrategy.
protected void executeCustomStrategy(CommandContext commandContext, JobEntity job, ActivityImpl activity) throws Exception {
FailedJobRetryConfiguration retryConfiguration = getFailedJobRetryConfiguration(job, activity);
if (retryConfiguration == null) {
executeStandardStrategy(commandContext);
} else {
if (isFirstJobExecution(job)) {
// then change default retries to the ones configured
initializeRetries(job, retryConfiguration.getRetries());
} else {
LOG.debugDecrementingRetriesForJob(job.getId());
}
List<String> intervals = retryConfiguration.getRetryIntervals();
int intervalsCount = intervals.size();
int indexOfInterval = Math.max(0, Math.min(intervalsCount - 1, intervalsCount - (job.getRetries() - 1)));
DurationHelper durationHelper = getDurationHelper(intervals.get(indexOfInterval));
job.setLockExpirationTime(durationHelper.getDateAfter());
logException(job);
decrementRetries(job);
notifyAcquisition(commandContext);
}
}
use of org.camunda.bpm.engine.impl.calendar.DurationHelper in project camunda-bpm-platform by camunda.
the class DurationHelperTest method shouldNotExceedNumberNegative.
@Test
public void shouldNotExceedNumberNegative() throws Exception {
ClockUtil.setCurrentTime(parse("19700101-00:00:00"));
DurationHelper dh = new DurationHelper("R2/PT10S/1970-01-01T00:00:50");
ClockUtil.setCurrentTime(parse("19700101-00:00:20"));
assertEquals(parse("19700101-00:00:30"), dh.getDateAfter());
ClockUtil.setCurrentTime(parse("19700101-00:00:35"));
assertEquals(parse("19700101-00:00:40"), dh.getDateAfter());
}
use of org.camunda.bpm.engine.impl.calendar.DurationHelper in project camunda-bpm-platform by camunda.
the class DurationHelperTest method shouldNotExceedNumber.
@Test
public void shouldNotExceedNumber() throws Exception {
ClockUtil.setCurrentTime(new Date(0));
DurationHelper dh = new DurationHelper("R2/PT10S");
ClockUtil.setCurrentTime(new Date(15000));
assertEquals(20000, dh.getDateAfter().getTime());
ClockUtil.setCurrentTime(new Date(30000));
assertNull(dh.getDateAfter());
}
Aggregations