Search in sources :

Example 1 with DurationHelper

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;
    }
}
Also used : ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) DurationHelper(org.camunda.bpm.engine.impl.calendar.DurationHelper) Expression(org.camunda.bpm.engine.impl.el.Expression) FailedJobRetryConfiguration(org.camunda.bpm.engine.impl.bpmn.parser.FailedJobRetryConfiguration) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) NotValidException(org.camunda.bpm.engine.exception.NotValidException)

Example 2 with DurationHelper

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());
}
Also used : DurationHelper(org.camunda.bpm.engine.impl.calendar.DurationHelper) Test(org.junit.Test)

Example 3 with DurationHelper

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);
    }
}
Also used : DurationHelper(org.camunda.bpm.engine.impl.calendar.DurationHelper) FailedJobRetryConfiguration(org.camunda.bpm.engine.impl.bpmn.parser.FailedJobRetryConfiguration)

Example 4 with DurationHelper

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());
}
Also used : DurationHelper(org.camunda.bpm.engine.impl.calendar.DurationHelper) Test(org.junit.Test)

Example 5 with DurationHelper

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());
}
Also used : DurationHelper(org.camunda.bpm.engine.impl.calendar.DurationHelper) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DurationHelper (org.camunda.bpm.engine.impl.calendar.DurationHelper)5 Test (org.junit.Test)3 FailedJobRetryConfiguration (org.camunda.bpm.engine.impl.bpmn.parser.FailedJobRetryConfiguration)2 Date (java.util.Date)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 NotValidException (org.camunda.bpm.engine.exception.NotValidException)1 Expression (org.camunda.bpm.engine.impl.el.Expression)1 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)1