Search in sources :

Example 6 with DurationHelper

use of org.activiti.engine.impl.calendar.DurationHelper in project Activiti by Activiti.

the class DurationHelperTest method daylightSaving23HourDayEurope.

@Test
public void daylightSaving23HourDayEurope() throws Exception {
    Clock testingClock = new DefaultClockImpl();
    testingClock.setCurrentCalendar(parseCalendar("20140330-00:00:00", TimeZone.getTimeZone("Europe/Amsterdam")));
    DurationHelper dh = new DurationHelper("R2/2014-03-30T00:00:00/P1D", testingClock);
    assertEquals(parseCalendar("20140331-00:00:00", TimeZone.getTimeZone("Europe/Amsterdam")), dh.getCalendarAfter(testingClock.getCurrentCalendar()));
}
Also used : DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) DurationHelper(org.activiti.engine.impl.calendar.DurationHelper) Clock(org.activiti.engine.runtime.Clock) Test(org.junit.Test)

Example 7 with DurationHelper

use of org.activiti.engine.impl.calendar.DurationHelper in project Activiti by Activiti.

the class JobRetryCmd method execute.

public Object execute(CommandContext commandContext) {
    JobEntity job = commandContext.getJobEntityManager().findJobById(jobId);
    if (job == null) {
        return null;
    }
    ActivityImpl activity = getCurrentActivity(commandContext, job);
    ProcessEngineConfiguration processEngineConfig = commandContext.getProcessEngineConfiguration();
    if (activity == null || activity.getFailedJobRetryTimeCycleValue() == null) {
        log.debug("activitiy or FailedJobRetryTimerCycleValue is null in job " + jobId + "'. only decrementing retries.");
        job.setRetries(job.getRetries() - 1);
        job.setLockOwner(null);
        job.setLockExpirationTime(null);
        if (job.getDuedate() == null) {
            // add wait time for failed async job
            job.setDuedate(calculateDueDate(commandContext, processEngineConfig.getAsyncFailedJobWaitTime(), null));
        } else {
            // add default wait time for failed job
            job.setDuedate(calculateDueDate(commandContext, processEngineConfig.getDefaultFailedJobWaitTime(), job.getDuedate()));
        }
    } else {
        String failedJobRetryTimeCycle = activity.getFailedJobRetryTimeCycleValue();
        try {
            DurationHelper durationHelper = new DurationHelper(failedJobRetryTimeCycle, processEngineConfig.getClock());
            job.setLockOwner(null);
            job.setLockExpirationTime(null);
            job.setDuedate(durationHelper.getDateAfter());
            if (job.getExceptionMessage() == null) {
                // is it the first exception 
                log.debug("Applying JobRetryStrategy '" + failedJobRetryTimeCycle + "' the first time for job " + job.getId() + " with " + durationHelper.getTimes() + " retries");
                // then change default retries to the ones configured
                job.setRetries(durationHelper.getTimes());
            } else {
                log.debug("Decrementing retries of JobRetryStrategy '" + failedJobRetryTimeCycle + "' for job " + job.getId());
            }
            job.setRetries(job.getRetries() - 1);
        } catch (Exception e) {
            throw new ActivitiException("failedJobRetryTimeCylcle has wrong format:" + failedJobRetryTimeCycle, exception);
        }
    }
    if (exception != null) {
        job.setExceptionMessage(exception.getMessage());
        job.setExceptionStacktrace(getExceptionStacktrace());
    }
    // Dispatch both an update and a retry-decrement event
    ActivitiEventDispatcher eventDispatcher = commandContext.getEventDispatcher();
    if (eventDispatcher.isEnabled()) {
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, job));
        eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_RETRIES_DECREMENTED, job));
    }
    if (processEngineConfig.isAsyncExecutorEnabled() == false) {
        JobExecutor jobExecutor = processEngineConfig.getJobExecutor();
        JobAddedNotification messageAddedNotification = new JobAddedNotification(jobExecutor);
        TransactionContext transactionContext = commandContext.getTransactionContext();
        transactionContext.addTransactionListener(TransactionState.COMMITTED, messageAddedNotification);
    }
    return null;
}
Also used : JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) ActivitiException(org.activiti.engine.ActivitiException) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) DurationHelper(org.activiti.engine.impl.calendar.DurationHelper) JobExecutor(org.activiti.engine.impl.jobexecutor.JobExecutor) TransactionContext(org.activiti.engine.impl.cfg.TransactionContext) JobAddedNotification(org.activiti.engine.impl.jobexecutor.JobAddedNotification) ActivitiException(org.activiti.engine.ActivitiException) ActivitiEventDispatcher(org.activiti.engine.delegate.event.ActivitiEventDispatcher)

Example 8 with DurationHelper

use of org.activiti.engine.impl.calendar.DurationHelper in project Activiti by Activiti.

the class DurationHelperTest method shouldNotExceedNumberPeriods.

@Test
public void shouldNotExceedNumberPeriods() throws Exception {
    Clock testingClock = new DefaultClockImpl();
    testingClock.setCurrentTime(parse("19700101-00:00:00"));
    DurationHelper dh = new DurationHelper("R2/1970-01-01T00:00:00/1970-01-01T00:00:10", testingClock);
    testingClock.setCurrentTime(parse("19700101-00:00:15"));
    assertEquals(parse("19700101-00:00:20"), dh.getDateAfter());
    testingClock.setCurrentTime(parse("19700101-00:00:30"));
    assertEquals(parse("19700101-00:00:30"), dh.getDateAfter());
}
Also used : DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) DurationHelper(org.activiti.engine.impl.calendar.DurationHelper) Clock(org.activiti.engine.runtime.Clock) Test(org.junit.Test)

Example 9 with DurationHelper

use of org.activiti.engine.impl.calendar.DurationHelper in project Activiti by Activiti.

the class DurationHelperTest method daylightSaving23HourDay.

@Test
public void daylightSaving23HourDay() throws Exception {
    Clock testingClock = new DefaultClockImpl();
    testingClock.setCurrentCalendar(parseCalendar("20140309-00:00:00", TimeZone.getTimeZone("US/Eastern")));
    DurationHelper dh = new DurationHelper("R2/2014-03-09T00:00:00/P1D", testingClock);
    assertEquals(parseCalendar("20140310-00:00:00", TimeZone.getTimeZone("US/Eastern")), dh.getCalendarAfter(testingClock.getCurrentCalendar()));
}
Also used : DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) DurationHelper(org.activiti.engine.impl.calendar.DurationHelper) Clock(org.activiti.engine.runtime.Clock) Test(org.junit.Test)

Example 10 with DurationHelper

use of org.activiti.engine.impl.calendar.DurationHelper in project Activiti by Activiti.

the class DurationHelperTest method daylightSavingFallFirstHour.

@Test
public void daylightSavingFallFirstHour() throws Exception {
    Clock testingClock = new DefaultClockImpl();
    testingClock.setCurrentCalendar(parseCalendar("20131103-05:45:00", TimeZone.getTimeZone("UTC")));
    Calendar easternTime = testingClock.getCurrentCalendar(TimeZone.getTimeZone("US/Eastern"));
    DurationHelper dh = new DurationHelper("R2/2013-11-03T01:45:00-04:00/PT1H", testingClock);
    assertEquals(parseCalendar("20131103-06:45:00", TimeZone.getTimeZone("UTC")), dh.getCalendarAfter(easternTime));
}
Also used : DefaultClockImpl(org.activiti.engine.impl.util.DefaultClockImpl) DurationHelper(org.activiti.engine.impl.calendar.DurationHelper) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Clock(org.activiti.engine.runtime.Clock) Test(org.junit.Test)

Aggregations

DurationHelper (org.activiti.engine.impl.calendar.DurationHelper)15 DefaultClockImpl (org.activiti.engine.impl.util.DefaultClockImpl)14 Clock (org.activiti.engine.runtime.Clock)14 Test (org.junit.Test)14 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 Date (java.util.Date)1 ActivitiException (org.activiti.engine.ActivitiException)1 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)1 ActivitiEventDispatcher (org.activiti.engine.delegate.event.ActivitiEventDispatcher)1 TransactionContext (org.activiti.engine.impl.cfg.TransactionContext)1 JobAddedNotification (org.activiti.engine.impl.jobexecutor.JobAddedNotification)1 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)1 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1